Using namespaces in C# using mono - c#

I am trying to run a C# program in linux using mono gmcs compiler. I need to include a namespace Microsoft.Boogie. I have the source code for the C# package which defines Boogie namespace. But when I try to use
using Microsoft.Boogie;
the compiler (gmcs) complains that
boogieTrace.cs(2,17): error CS0234: The type or namespace name `Boogie' does not
exist in the namespace `Microsoft'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
Does anyone know how to include custom namespaces in a C# program?

Related

CS0246: The type or namespace name 'MySql' could not be found

how i can fix this problem??
help me
Compiler Error Message: CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?)
Line 1: using MySql.Data.MySqlClient;
Apologies if this is not the case but working on the assumption that you're developing in a version of Visual Studio, check the project references.
If MySql.Data exists in the references but has the warning (yellow triangle) indicator next to it then you may need to re-reference the .dll from its location in your filesystem.
Alternatively, you can grab this from the Nuget package manager if it is not available locally.
Despite the full namespace qualification, the library must be correctly referenced for the object namespace to be recognised in the IDE.
Let us know what IDE you're using if not VS.

Mono compile error due to namespace name does not exists

I'm using mono on macOS and trying to compile this C# code: https://gist.github.com/bneg/bf8c05664324e3efeb1fb05902152a20
with following command:
mcs Program.cs
It produces following error:
Program.cs(4,14): error CS0234: The type or namespace name `Management' does not exist in the namespace `System'. Are you missing an assembly reference?
Program.cs(5,14): error CS0234: The type or namespace name `Management' does not exist in the namespace `System'. Are you missing an assembly reference?
I also tried it with following command:
mcs -pkg:dotnet Program.cs
I got this error:
Program.cs(17,25): error CS0234: The type or namespace name `Automation' does not exist in the namespace `System.Management'. Are you missing an assembly reference?
Program.cs(18,25): error CS0234: The type or namespace name `Automation' does not exist in the namespace `System.Management'. Are you missing an assembly reference?
What changes should be made in order to compile it?
I'm not sure if you can run powershell like that via mono on mac os.
As a minimum you would need to reference something like this:
https://www.nuget.org/packages/System.Management.Automation
But this is not guaranteed to be working if you do not have powershell installed. And since powershell on linux (sic!) can only run on .net core, chances are, you cannot get what you are trying to accomplish.

Adding assembly references for compiling with developement console

I'm trying to compile a file using System.Numerics but I have to add the assembly reference. Long story short Visual Studio isn't working and it's now less simply problematic to do the compiling in the Dev Command Prompt. What would I have to do get the assembly reference working for the command promt. I've been looking but all I've found was how to add the reference in Visual Studio.
The compiler version is Microsoft (R) Visual C# Compiler version 2.2.0.61624
The using statements in the beginning are as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Task;
using System.Numerics;
The error code is:
Ctst2.cs(7,14): error CS0234: The type or namespace name 'Numerics' does not exist in the namespace 'System' (are you missing an assembly reference?)
I am going to assume that you are trying to use the command-line C# compiler csc.exe.
If you type csc.exe /? the compiler will show you the list of all available options. Among them, you will find the -reference option that allows you to add assembly references on the command line.
Example, in your specific case:
csc Ctst2.cs -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Numerics.dll"
The above is all one long command line that you would type without hitting [enter] until the very end. You may have to change the path to System.Numerics.dll to correspond to your version of the .NET Framework.
Also, take a look at https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/reference-compiler-option for an in-depth discussion of the -reference option.

How to reference System.Threading.Tasks, MySql and MysqlConnection with Mono

I am trying to run a C# console application on my server which is running Ubuntu Server 12.04. I have installed Mono JIT version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2) and additional packages like gmcs and MonoDevelop. The file that I am trying to execute is called Program.cs and when I run the command $gmcs Program.cs I get the following errors:
error CS0234: The type or namspace name 'Tasks' does not exist in the namespace 'system.Threading'. Are you missing assembly reference?
error CS0246: The type or namespace name 'MySql' could not be found. Are you missing a using directive or an assembly reference?
error CS0246: The type or namespace name 'MySqlConnection' could not be found. Are you missing a using directive or an assembly reference?
I have researched into referencing the .dll files for the above namespaces but have not been able to find an answer that is clear. Most forum links suggest that I install mono - trunk, but I want to know if I should uninstall the existing mono package and then install mono-trunk.
I am new to the Unix platform and researching every step of my way. Your help will be much appreciated.
If you are compiling from the command line, you will need to pass the referenced assemblies as a series of /r or /pkg switches, such as:
mcs /r:MySql.Data.dll Program.cs
Obviously you will need to have the required assemblies installed too.
Also note that gmcs is an (old) alias for the .net 2.0 compiler, that's why it doesn't see System.Threading.Tasks (which is a .net 4 feature). See the -sdk switch of mcs.
You should probably install monodevelop to have a user-friendly IDE to help you.

The type or namespace name 'Exchange' does not exist in the namespace

When I run my ASP.net app I get this error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'Exchange' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Source Error:
Line 06: using System.Web.UI.WebControls;
Line 07: using System.Data.OleDb;
Line 08: using Microsoft.Exchange.WebServices.Data; // error
Line 09: using System.Net;
Line 10: using System.Data.SqlClient;
Make sure your Target Framework versions match in all projects of your solution. I personally have had issues with .NET Framework 4 Client Profile. Once I switched it to .NET Framework 4, it worked.
You are probably missing a reference to microsoft.exchange.webservices.dll assembly. At least the ASP.NET cannot find that assembly when it tries to compile the code.
This is a page compilation error. To resolve it you need to look into the compilation.assemblies configuration and pages.namespaces, which let you configure the assemblies and namespaces used in the generated code for pages. The other way to ensure assemblies are referenced during page compilation is to mark them as "Copy Local" in your solution.
In your case you are probably referencing an Exchange dll in your project. Mark it as "Copy Local" and the error should resolve.
If you want to use
using Microsoft.Exchange.WebServices.Data;
You have to install Microsoft.Exchange.WebServices via the NuGet manager.

Categories