Hi,

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;
        }

        mono_config_parse(NULL);

        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)))
{
        printf(mono_method_get_name(method));
        printf("\n");
}

Give me the following output:

.ctor
TestMe

Anyone have a idea to solve my problem?

Thanks!
__________________________________________________
Francois Schelling
Senior Programmer
Square Enix Montréal 







______________________________________________________________________
This email has been scanned by the MessageLabs
______________________________________________________________________
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to