[Mono-osx] ObjC library run from Mono always returns null

AlexGray alex.j.gray23 at gmail.com
Thu Aug 22 04:45:33 UTC 2013

I've got a simple objc library which has 1 static function, return a string,
which will only return null when run from mono. 

This is the source code of the library:
#import <Foundation/Foundation.h>

@interface DeviceGetter : NSObject
+ (NSString*)test;

@implementation DeviceGetter
+ (NSString *)test
    return @"test";
Which compiles to DeviceGetter.dylib.

I run bmac.exe on the following API definition file 

using System;
using MonoMac.Foundation;

[assembly: MonoMac.RequiredFramework("DeviceGetter.dylib")]
namespace Imaginality.Toolkit.NuonTK
	[BaseType (typeof (NSObject))]
	public interface DeviceGetter
		[Static, Export ("test")]
		string test(); 

And then in my final project I reference the compiled definition file and
include the DeviceGetter.dylib in the output directory.

And then as according to Duane in this thread
http://mono.1490590.n4.nabble.com/Binding-Objective-C-Types-td4656457.html I
make changes to AppDelegate as such: 

		public AppDelegate ()
			Type t = typeof(DeviceGetter);
			MonoMac.ObjCRuntime.Runtime.RegisterAssembly (t.Assembly);
			string a = DeviceGetter.test ();
			System.Diagnostics.Debug.Write (a);

But it never prints "test" as I would expect it to, instead the variable "a"
remains null.

If anyone can point out what i might be doing wrong that would be greatly

View this message in context: http://mono.1490590.n4.nabble.com/ObjC-library-run-from-Mono-always-returns-null-tp4660618.html
Sent from the Mono - OSX mailing list archive at Nabble.com.

More information about the Mono-osx mailing list