Hi Robert, thank you for your answer!

I've tried calling the default ctor using mono_runtime_object_init() on the
DateTime instance but I get an assertion:

ERROR:object.c:95:mono_runtime_object_init: assertion failed: (method)
Stacktrace:


Native stacktrace:

    /usr/lib64/libmono.so.0() [0x370d6a1e5a]
    /lib64/libpthread.so.0() [0x383ea0f440]
    /lib64/libc.so.6(gsignal+0x35) [0x383e2329a5]
    /lib64/libc.so.6(abort+0x175) [0x383e234185]
    /lib64/libglib-2.0.so.0(g_assertion_message+0x144) [0x383fe61ea4]
    /lib64/libglib-2.0.so.0() [0x383fe62450]
    /usr/lib64/libmono.so.0(mono_object_get_virtual_method+0) [0x370d770cc0]
    ./test-invoke() [0x401edc]
    /lib64/libc.so.6(__libc_start_main+0xfd) [0x383e21ec5d]
    ./test-datetime() [0x401569]

I've also tried calling the inherited ctor from ValueType on the DateTime
instance but it makes no difference (the ToString method returns: 1/1/0001
12:00:03 AM).

Sorry for not commenting on this in my first email, I had tried that before
without success, so I thought I was doing something wrong or not doing
something (perhaps ValueTypes are special objects and have to do something
more than just calling the default ctor?).


Thank you again and any tips on this are more than welcome :)


Federico Omoto



On Sat, Oct 23, 2010 at 5:59 AM, Robert Jordan <[email protected]> wrote:

> On 23.10.2010 07:12, Fede wrote:
> > Hi!
> >
> > I've a problem when instantiating a DateTime class from C code and
> invoking
> > the ToString() method.
> > The code I've is as follows:
> >
> > class = mono_class_from_name(mono_get_corlib(), "System", "DateTime");
> > object = mono_object_new(domain, class);
> > method = mono_class_get_method_from_name(class, "ToString", 0);
> > string = (MonoString*)mono_runtime_invoke(method, object, NULL, NULL);
> > printf("%s\n", mono_string_to_utf8(string));
> >
> > It ouputs: 1/1/0001 12:00:03 AM
> > when the same C# code (Console.WriteLine(new DateTime().ToString()))
> > outputs: 1/1/0001 12:00:00 AM
> >
> > What am I doing wrong?
>
> You're not invoking a constructor on the DateTime instance.
> Assuming you want the default ctor, you can invoke it with:
>
> mono_runtime_object_init (object);
>
> Other non-default ctors need to be mono_runtime_invoked like
> any other method.
>
> RObert
>
> _______________________________________________
> Mono-list maillist  -  [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-list
>
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to