Frage

I need to create a console MonoMac application.

  1. Open Xamarin Studio and create C# console application project (not MonoMac specific).
  2. Add reference to MonoMac assembly.
  3. Edit Main method in Program.cs:

    using System;
    using MonoMac.Foundation;
    
    namespace ConsoleTest
    {
        class MainClass
        {
            public static void Main(string[] args)
            {
                Console.WriteLine(new NSString("Hello World!"));
            }
        }
    }
    

The project builds ok. But when I run it the console opens with error:

Missing method .ctor in assembly /.../ConsoleTest.exe, type MonoMac.Foundation.NSString

So the console project runs on Mac, but MonoMac assembly cannot be used. How to fix it?

War es hilfreich?

Lösung

Solved.

MonoMac should be compiled from sources:

  1. Clone https://github.com/mono/monomac (including submodules).
  2. Open terminal and run "make" in the root folder.
  3. Find MonoMac.dll in src folder and copy it to your project directory.
  4. Reference it directly (don't use the version bundled with Xamarin Studio).

One thing I also tried is to run NSApplication.Init() when starting the app. It seems a working solution too.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top