GLib: Cannot convert message. crash

I have a problem writing a .net plugin. The plugin contains only one class. During Initialisation of that class some EventHandlers are setup. Everytime i register an EventHandler

OnEvent += MyEventHandler;

Unity crashes. Before the crash a Windows message box pops up (on vista) reporting an error, but doesn't display a message. The Editor.log says this:

GLib: Cannot convert message: Conversion from character set 'UTF-8' to 'CP1252' is not supported

Any idea what's going on there?

Edit: In the editor.log just after the above line there is another error reported:

** Error **: file ..\..\mono\metadata\marshal.c: line 527: assertion failed: (found)


No idea why someone triggers assertions without useful information...

Not too long ago someone else brought up the same error message when attempting to use F#. I've seen that error before, and I consider it basically a bad stuff happened message - usually the actual error has nothing whatsoever to do with character conversion.

Is your library Unity-dependent, that is, does it use any of the UnityEngine classes? If not, you may want to try it on a standalone executable first, to a) determine if the error is actually caused by using it inside Unity, and b) try and get a better error message / stack trace.

I don't have Pro version, (can't experiment with plugins), so this is a shot in the dark :) One thing I remember reading (somewhere) is that Unity C# is slightly different in how it compiles, so that code which doesn't give an error in Visual C# Express, might do so in Unity. So even though the code is correct, I suggest modifying it anyway, trying different ways of implementing the same operation - maybe one will click with Unity.

For instance, I don't know what the rest of your code looks like or how you create your event handler, but I've seen sample code that creates and assigns it on one line, with a new, like:

b1.Click += new EventHandler(OnClick);

Try re-arranging your code, maybe something will bypass the error. Like I said, shot in the dark :) . And I presume you've put in tons of Debugging statements, made sure nothing is null, etc.

Or maybe it's not the registration - you might post the code in the Handler, maybe there's something in there Unity doesn't like. Or remove its code, turn it into a stub, see if the error persists.

Came across this error today - turned out to be a duplicate case statement in a switch. So not a very useful error message ...

Not sure, but could it be that you are targeting a newer version of CLR? Could you try to target CLR version 2.0 or older?