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

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.

Related

xsp npgsql C#.aspx

Running: on bsd unix in a controlled environment with matching builds.
Running: xsp4 --port 8022 --nonstop --verbose
This works perfectly with C# until I add using npgsql; to the C# program:
Compiler Error Message: CS0246: The type or namespace name `Npgsql' could not be found. Are you missing a using directive or an assembly reference?
Note: I can create and run a mono program no errors with this directive:
mcs -r:/sdf/sys/pkg6_amd64/lib/mono/4.0/Npgsql -r:System.Data Npgsql1.cs
I have tried the npgsql and mono web site, stack overflow, google. Please suggest how to start xsp4 so npgsql can be found.
I checked the error web page "'Npgsql' could not be found."
There was a link to compiler options and the second link one was
libs=myhomepage/bin
I copied the Npgsql.dll into that bin directory and it worked perfectly.
David

Missing Automation from namespace 'System.Management'. Missing assembly reference

System: Windows 7 Professional 64 bit, PowerShell v 2.0, no Visual Studio (can't be installed and others too)
Trying to run PowerShell from C#. This is the code snippet:
using System;
using System.Management.Automation;
class Hello {
static void Main(string[] args) {
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
Console.WriteLine("Process Id");
Console.WriteLine("----------------------------");
foreach (PSObject result in ps.Invoke()) {
Console.WriteLine(
"{0,-24}{1}",
result.Members["ProcessName"].Value,
result.Members["Id"].Value);
}
}
}
Error:
e:\foo.cs(2,25): error CS0234: The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
Since no Visual Studio is there, I am running code in raw manner. Because of error, I downloaded dll from http://www.dll-found.com/system.management.automation.dll_download.html and placed in dir as per instruction. After rebooting machine, there was no success.
First, I want to ask a general question. How to install missing assembly or dll file (only), because for some you might have to install whole Windows or PowerShell SDK or .NET Framework.
EDIT
I have place downloaded dll file in C:\Windows\SysWOW64, C:\Windows\system32, C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 and C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0.
I am compiling using:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:exe /out:E:\foo.exe E:\foo.cs
WARNING: Never ever download DLLs from random websites in any sane situation. Use NuGet packages (or whatever your preferred package manager is for your project) whenever possible. If a DLL is not found, there is almost always a good reason for it, and you need to find out what it is and fix it, not just get the DLL from the internet.
If you have this problem after re-targeting an old project to, for example, .NET 4.8, then it is because NuGet package names have changed.
Uninstall the package System.Management.Automation
Install the package Microsoft.PowerShell.5.1.ReferenceAssemblies (NuGet)
This package name appears in the documentation of classes in the namespace System.Management.Automation.
NuGet worked for me.
PM> Install-Package System.Management.Automation.dll -Version 10.0.10586
You must use /reference command line parameter to csc.exe, described in MSDN:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /reference:system.management.automation.dll /target:exe /out:E:\foo.exe /E:\foo.cs

CSC with C# Command For MySQL

I am still learning c# and have been following a tutorial where I use Visual Studio to connect MySQL. I want to compile the file using csc on the command line this time and error cs0246 came out6 where its ays "The type or namespace name 'MySqlConnection' could not be found (are you missing a using directive or assembly reference?)".
I am just using the command "csc MyFile.cs". I know that I should be using some form of directive but I'm not sure how to use it? In Visual Studio, all I have to do is add the MySql.Data and MySql.Data.Entity into the Reference under the project. How do I use the csc command?
csc /? contains all answers... Also covered in Working with the C# 2.0 Command Line Compiler.
Will be something like (not sure what is the name/path of assembly you need to link):
csc /reference:MySqlConnection.dll MyFile.cs

Compile a C# visual studio console application in mono (mac)

I am pretty new to mono and C# so this is probably a simple question, but i cannot find the answer.
I need to compile a C# visual studio console application on my mac. I thought mono would be right for that purpose. I don't know which file to compile and took program.cs (where my main function is) or should i compile Project.csproj.
When i run
gmcs Program.cs
I get
Program.cs(17,16): error CS0246: The type or namespace name `Oplossing' could not be found. Are you missing an assembly reference?
Program.cs(129,54): error CS0246: The type or namespace name `Order' could not be found. Are you missing an assembly reference?
What en how should i compile?
Via xbuild, you should be able to compile csproj directly,
http://www.mono-project.com/Microsoft.Build
Unless you are working on a system without a ui, (since you are targetting macos you have a ui) download and install Monodevelop and open the visual studio project with that.
Otherwise check the (g) mcs documentation
The way to use it is already in te comments here
Note: you do NOT have to recompile your app on MacOs to run it on MacOS, just copy the exe (assembly) to your mac and execute it with mono

Shared classes are build under VS2008 only but not under MSBuild

We share our classes between silverlight 3.0 client and server as is it described here. Everything works fine under Visual Studio 2008 only. Using msbuild with following command line parameters:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe FoobarApplication.sln /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU"
we get following error:
Class1.cs(28,54): error CS0234: The type or namespace name 'WcfService' does not exist in the namespace 'Company.FoobarApplication' (are you missing an assembly reference?)
Service References\geoServiceReference1\Reference.cs(24,81): error CS0234: The type or namespace name 'WcfService' does not exist in the namespace 'Company.FoobarApplication' (are you missing an assembly reference?)
Done Building Project "C:\work\bov-tmp\FoobarApplication\SilverlightClassLibrary3\SilverlightClassLibrary3.csproj" (Rebuild target(s)) -- FAILED.
Done Building Project "C:\work\bov-tmp\FoobarApplication\FoobarApplication.sln" (Rebuild target(s)) -- FAILED.
I found exactly the same question here. There are 4 workarounds there, I tried first 3 of them and those did not worked out. The 4-th workaround is not the acceptable solution.
Any thoughts how to build the solution?
Resolved the problem. The geoServiceReference1 project was referencing our RUI.Web project. That stupid reference appeared somehow after the solution reorganization.

Categories