Guy
Guy

Reputation: 413

Why can't I target Mono in VS2010 on Windows?

I have downloaded and installed the Mono framework onto my Win7 development machine. I then followed the instructions here to have Visual Studio 2010 allow targeting of the Mono framework instead of .NET. I then create this test console app using VB with the target framwework set "Mono 2.10.8 profile" in the project's Advanced Compile Options:

Dim runningOnMono As Boolean = Not IsNothing(Type.GetType("Mono.Runtime"))
Console.WriteLine("Running on Mono =  " & runningOnMono.ToString)

When I run this on the Win7 dev machine it returns False i.e. not running on Mono. When I run the program on a Linux machine that only has Mono installalled it returns True.

I can reference parts of the Mono framework in VS and intellisense works, but when I make this call:

Dim monoinf As New Mono.Unix.UnixDriveInfo("g:")

I get this exception:

===================================

FileNotFoundException was unhandled: Could not load file or assembly 'Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.

===================================

Mono.Posix.dll version 4.0.0.0 does exist in many directories including the one created specifically for the VS Mono profile. I even tried copying it to the test app's directory.

Is it just that my mono install on the Win7 box is a mess? How can it be that intellisense works but the call to Type.GetType("Mono.Runtime") returns Nothing ?

The resaon I am trying to target Mono is because the class System.IO.DriveInfo does not work on Mono so I think I have to use Mono.Unix.UnixDriveInfo if I want to run on Windows and Linux. I need to get the free space of a USB flash drive.

Thanks for any help.

Upvotes: 1

Views: 451

Answers (1)

Lex Li
Lex Li

Reputation: 63295

You already target Mono by following the blog post, but you should use mono.exe to launch your executable (test.exe as example) at Mono command prompt,

mono.exe test.exe

That's the only way Mono runtime is loaded instead of .NET Framework on Windows.

Upvotes: 1

Related Questions