[Mono-list] Missing .ctor

Francois Schelling fschelling at square-enix-montreal.com
Tue Aug 7 20:32:42 UTC 2012


I'm new with Mono and I'm having a problem to get my project running.  I've created a C++ console application in which I would like to embed a C# dll.  I'm able to open my C# dll but once I try to invoke a function on my C# object, I got the following error:

Missing method .ctor in assembly D:\projects\monoscripting\monoscripting\monoscript.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
Can't find custom attr constructor image: D:\projects\monoscripting\monoscripting\monoscript.dll mtoken: 0x0a00000d

I'm using Mono 2.10.8 with Visual Studio 2010.

My CS class look like this :

class ScriptTest
public ScriptTest() { }

void TestMe()
	Console.WriteLine("Hello %f\n", m_Test);

public float m_Test = 0;

My C++ main() looks like this:

int main(int argc, char* argv[])
	mono_set_dirs("mono/lib", "mono/etc"); 
	MonoDomain* domain = mono_jit_init("monoscripting.exe");

	MonoAssembly* assembly;
	assembly = mono_domain_assembly_open (domain, "monoscript.dll");
	if (!assembly)
		return 1;


	MonoImage* image = mono_assembly_get_image( assembly );
	if (!image)
		return 1;

	const char* ns = "monoscript";
	const char* name = "ScriptTest";
	MonoClass* klass = mono_class_from_name (image, ns, name);
	if (!klass)
		return 1;
	// Create a new instance of the class.
	MonoObject* object = mono_object_new( domain, klass );

	// Get the constructor of the class.
	MonoMethod* constructorMethod = mono_class_get_method_from_name( klass, ".ctor", 0);
	MonoObject* pException = NULL;
	mono_runtime_invoke (constructorMethod, object, NULL, &pException);


I've added the following code to see the content of my class and the constructor seems to be there:

void* iter = NULL;
while ((method = mono_class_get_methods (klass, &iter)))

Give me the following output:


Anyone have a idea to solve my problem?

Francois Schelling
Senior Programmer
Square Enix Montréal 

This email has been scanned by the MessageLabs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20120807/83bff89c/attachment-0001.html>

More information about the Mono-list mailing list