Can't get System.Numerics to work with command-line Mono (mcs) on OS X - mono

We're trying to run a simple Mono script on the command line on OS X. Most scripts work fine for us, but as soon as we try to use System.Numerics, we get "error CS0234: The type or namespace name `Numerics' does not exist in the namespace System."
This isn't too surprising, and should be fixable with an appropriate command-line option to mcs, plus properly set up PKG_CONFIG_PATH... but this is where we get stumped. First, here's the script so you can follow along at home:
using System;
using System.Numerics;
public static class MainProgram {
public static void Main(string[] args) {
Console.WriteLine("Hello world!");
}
}
So next we tried "mcs -r:System.Numerics Test.cs". This produces "error CS0006: Metadata file `System.Numerics' could not be found".
"man mcs" suggests that we can get the other system packages by adding "-pkg:dotnet" to the command line. But that produces:
Package dotnet was not found in the pkg-config search path. Perhaps
you should add the directory containing `dotnet.pc' to the
PKG_CONFIG_PATH environment variable No package 'dotnet' found error
CS8027: Error running pkg-config. Check the above output.
OK then, we had no PKG_CONFIG_PATH, so we tried defining one:
export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/
This fixes the CS8027; but we still get the CS0234 we started with. And if I combine the -pkg and the -r, e.g. "mcs -pkg:dotnet -r:System.Numerics Test.cs", I get "error CS0006: Metadata file `System.Numerics' could not be found".
I'm stumped at this point... any idea what incantation I'm missing to make System.Numerics work with mcs?

If you're using Mono 2.10.x, you will have to compile with dmcs rather than mcs to enable the 4.0 profile (System.Numerics is a C# 4.0+ feature only).
If you're using Mono 2.11.x or 3.0.x, then mcs by default should select the 4.5 profile. mcs -help should show 2, 4, and 4.5 as possible values for the -sdk option. If it doesn't, then the framework isn't properly installed; I had that once, where I think that /Library/Frameworks/Mono.framework/Versions/Current pointed to the wrong directory; installing a second time fixed that.
Manipulating pkg-config should be unnecessary.

Related

Can not compile xUnit test classes (via mono) to exe file, using mcs command

I am using MSYS2 and mono in order to run C# project (in .NET Framework) in Linux environment on Windows machine.
My projects are placed in the path: D:\MyRootPath and there I have two separate solutions:
D:\MyRootPath\MainProject - this is my main project;
D:\MyRootPath\xUnitProject- this is a separate solution that contains project that I use for unit testing with xUnit.net framework (for .NET Framework);
Building main project (working sample)
Inside of D:\MyRootPath\MainProject I have a sample class D:\MyRootPath\MainProject\HelloWorld.cs:
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello Mono World");
}
}
When I want to build this via mono, to create an .exe file and run it, I am using the following commands inside of the MSYS2 console (this approach is working well):
mcs /d/MyRootPath/MainProject/HelloWorld.cs
mono /d/MyRootPath/MainProject/HelloWorld.exe
Building xunit project (need help here)
Inside of the xUnitProject, I have many classes, where each class represent a test case (and each test case have reference to the main project - MainProject.dll). One example of test case is D:\MyRootPath\xUnitProject\SampleRectangle.cs:
using MainProject;
using System;
using Xunit;
namespace xUnitProject
{
public class SimpleRectangle
{
[Fact]
public void simpleRectangle()
{
//this content is irrelevant to the question, I have a few Assert checks
Assert.Equal("someVariable", someVariable);
Assert.Equal("someOtherVarialble", someOtherVarialble);
}
}
}
Here I need to build this via mono, to create an .exe file and run it. Since I have many classes like SimpleRectangle, I need to run them all and to have separate .exe files for each.
So I am trying to build the test classes with the following (similar as above working example):
mcs /d/MyRootPath/xUnitProject/SampleRectangle.cs -r:/d/MyRootPath/xUnitProject/bin/Debug/MainProject.dll:/d/MyRootPath/xUnitProject/bin/Debug/xunit.core.dll
where I had to add -r flag, since it points to the .dll files that are used.
The output that I got is:
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0012: The type `System.Attribute' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
D:\MyRootPath\xUnitProject\bin\Debug\xunit.core.dll (Location of the symbol related to previous error)
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0103: The name `Assert' does not exist in the current context
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0103: The name `Assert' does not exist in the current context
error CS5001: Program `SimpleRectangle.exe' does not contain a static `Main' method suitable for an entry point
Compilation failed: 4 error(s), 0 warnings

When importing Nim module for Lua bindings, error shows: "could not load: lua(|5.1|5.0).dll"

I'm new to the Nim programming language, and coming from a Lua background, it excited me to find out that there is a module for adding Lua bindings to Nim.
I installed Nimble (Nim's package manager) for Windows and executed "nimble install lua" to download and install the correct module. Upon trying to import it and compile the source, this happened:
C:\Users\Ashley\Desktop\Stuff\Coding\Nim\Projects\LuaTest>nim c -r "C:\Users\Ashley\Desktop\Stuff\Coding\Nim\Projects\LuaTest\main.nim"
Hint: system [Processing]
Hint: main [Processing]
Hint: lua [Processing]
CC: main
CC: lua_lua
Hint: [Link]
Hint: operation successful (10698 lines compiled; 1.262 sec total; 16.163MB; Debug Build) [SuccessX]
could not load: lua(|5.1|5.0).dll
Error: execution of an external program failed: 'c:\users\ashley\desktop\stuff\coding\nim\projects\luatest\main.exe '
I have Lua 5.1 already installed with the proper entries in PATH. It's located in Program Files (x86). The directory contains a dll called lua5.1.dll. I tried looking up the error on Google, but there were no results that helped. What could be the problem?
On Windows you can put the library at the same place as the generated binary. In this case the file should be called lua.dll, lua5.1.dll or lua5.0.dll. Also make sure that the library and binary are both for the same system architecture, either x86 (32bit) or x86-64 (64bit).

servicehost constructor doesn't initialize its members in linux (mono - vb.net)

I wrote a simple program since my application doesn't work in mono. But even that simple program doesn't work and I understand is the ServiceHost constructor that doens't initialize its member (despite the fact that in mono source code you can see correct instructions).
I use mono/.net 4.0 ('mono --version' says 4.0.1, monodevelop 5.10, ubuntu 14.04.2 lts (32bit). I've tried to add the dll needed (ver 4.0) in the exe path, but nothing change.
That's the easy code I uses (in .Net no errors, in linux "invalid IL code in System.ServiceModel.ServiceHostBase:get_Credentials() : IL_0000 ret").
Imports System.Security.Cryptography.X509Certificates
Imports System.servicemodel
Public Interface IMyService
Sub DoSomething()
End Interface
Public Class CMyService
Implements IMyService
Public Sub DoSomething() Implements IMyService.DoSomething
Console.WriteLine("-dosomething-")
End Sub
End Class
Module Module1
Sub Main()
Dim h As New ServiceHost(GetType(CMyService), New System.Uri("net.tcp://127.0.0.1/10000"))
'if you check 'h', you'll see all its member set to Nothing :(
h.Credentials.ClientCertificate.Authentication.CertificateValidationMode = Security.X509CertificateValidationMode.None
End Sub
End Module
It is compiled succesfully but it throws an exception if executed.
As reported on source code, if you check members of variable 'h' I have all its items set to 'Nothing'.
I've tried using 32bit and 64bit exe compiled on Windows 7 using Xamarin Studio and Visual Studio (they work great on Windows, but same error in mono). I used in ubuntu the dll copied from Windows .net 4.0. Obviously the 64bit version doesn't even start. I even compiled inside linux using monodevelop 5.10 but I get the same runtime error.
I changed "System.Security.Criptography.X509Certificates" in "Mono.Security.Criptography.X509Certificates" changing also the dll, but in linux I have the same error invariably.
What can I do/check?
I'm stuck for 2 days :/
Thank you in advance.
Update 1
I converted the source code in c#, compiled with mcs, which suggests using also System.IdentityModel.dll. The application in c# works this way. I then update the project in monodevelop, it compile and I can do step-by-step in that IDE.
Then I updated the vb.net project, adding the "missing" dll. It compiles again correctly under monodevelop and the step-by-step debug stops again for the same reason.
Then I compiled using vbnc and it works. But I cannot debug inside the IDE.
I cannot understand why... I hope I must not convert all my source code to C# to see other "missing dll", and guess strange behavour of monodevelop...
Maybe I try to add the 'missing' dll in Windows 7, compile and see what linux says.
Update 2
Linux doesn't like the program compiled in Windows 7, it must be compiled in linux using vbnc by command line.
The problem was solved compiling the test program in linux with vbnc called by command line (for some unknown reason, monodevelop compile correctly only the c# version and not the equivalent version in vb.net).
So it's impossible to do a step-by-step debuggin using monodevelop and vb.net, but it works using c#.
During compilation in c# (using msc) a warning about a missing dll (System.Identity.dll) appears. Microsoft exe doesn't need it, mono does, but only msc tell you about it. I find info about it nowhere, so maybe it can be usefull to someone else... I was 3 days stuck on this :/

mono-test-install reveals I have a broken System.Drawing

I've gotten the tarball of Mono 3.0.3 from the mono project and compiled it on an Ubuntu 12.10 distro.
The configure, make and make install commands all ran without errors. I ran the mono-test-install and it reports "Your system has a broken System.Drawing setup". I'm not quite sure how to fix this or why it's broken. I have a valid libgdiplus.so file and pointed the configuration options to it.
It seems that I am unable to use the System.Drawing until I get this solved. Has anyone run into this before?
The way the mono-test-install script is testing the System.Drawing setup is to compile the code
using System;
using System.Drawing;
class X {
static void Main ()
{
Bitmap b = new Bitmap (100, 100);
}
}
using the command
mcs -pkg:dotnet <filename>
and then runs the resulting file with
mono <filename>.exe
You can do this process by hand to see the actual error message that caused mono to conclude that System.Drawing was broken, possibly allowing you to fix the problem.

Does mono 2.8 support 'dynamic' keyword?

I tested IronPython on mono 2.8 with the code in the book Professional IronPython p.315 listing 15-3.
using System;
using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
namespace Method2
{
class Program
{
static void Main(string[] args)
{
// Obtain the runtime.
var IPY = Python.CreateRuntime();
// Create a dynamic object containing the script.
dynamic TestPy = IPY.UseFile("TestClass.py");
// Execute the __test__() method.
TestPy.__test__();
}
}
}
I see it's compiled OK, and run without a problem on Windows 7, whereas the mono 2.8 gives me the following error message.
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
`Microsoft.Scripting.Hosting.ScriptScope' does not contain a definition for `__test__'
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1
(System.Runtime.CompilerServices.CallSite,object)
at Method2.Program.Main (string[])
I thought Mono 2.8 supports C# 4.0 which has the dynamic keyword, but I see that the 'dynamic' keyword is not fully supported with mono.
Is this a bug of Mono 2.8?
ADDED
This is the python script.
# The class you want to access externally.
class DoCalculations():
# A method within the class that adds two numbers.
def DoAdd(self, First, Second):
# Provide a result.
return First + Second
# A test suite in IronPython.
def __test__():
# Create the object.
MyCalc = DoCalculations()
# Perform the test.
print MyCalc.DoAdd(5, 10)
# Pause after the test session.
raw_input('\nPress any key to continue...')
This is the command that I used
dmcs Program.cs /r:System.Core /r:IronPython.dll /r:IronPython.Modules.dll /r:Microsoft.Dynamic.dll /r:Microsoft.Scripting.dll /r:Microsoft.CSharp.dll
It compiles well, but it still breaks when I run the execution binary. Do I need to have all the dlls in the same directory where the execution binary locates?
The fact that you are getting a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException means that the dynamic keyword worked. The problem you are having is that IPY.UseFile("TestClass.py"); is returning a ScriptScope that doesn't see your test method. So the problem lies with your python source or how you are including IronPython with mono.
The dynamic keyword is certainly supported by Mono 2.8 when using the C# 4 profile.
I guess my question is how you are building this sample?
Just for kicks, I just pasted your sample into MonoDevelop. I had to tell MonoDevelop to use C# 4 instead of C# 3.5 first of all.
The dynamic keyword was introduced in C# 4 obviously.
Also, I did have to include a few assembly references: System.Core, IronPython.dll, IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, and Microsoft.CSharp.dll. I am not sure if I needed them all.
If you are building from the command-line you need to use 'dmcs' as the compiler (to indicate the .NET 4 profile) and you need to include the assembly references.
It builds without problems with this configuration (for me at least).
I am responding to this question with respect to Mono 2.10.
I could successfully build and execute the code from command line on Windows 7 without using MonoDevelop. Here are the steps:
Install Mono 2.10.8 on Windows 7.
Install IronPython 2.7.2.1.
"C:\Program Files\Mono\bin" or equivalent and "C:\Program Files\IronPython 2.7" or equivalent should be part of system path.
Both TestClass.py and Program.cs should be in the same folder.
From the dos prompt, corresponding to the folder where TestClass.py and Program.cs exists, execute setmonopath batch file.
From the same dos prompt execute the following command:
dmcs Program.cs /r:System /r:"C:\Program Files\IronPython 2.7\IronPython.dll" /r:"C:\Program Files\IronPython 2.7\IronPython.Modules.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Dynamic.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Scripting.dll" /r:"C:\program Files\IronPython 2.7\Microsoft.Scripting.MetaData.dll" /r:Microsoft.Csharp
Program.exe should be successfully generated and the same can be executed without any error message.