[Mono-devel-list] ToString() in DateTime failed on embedded mono

Mohammad DAMT md at mt.web.id
Tue Jul 8 12:11:40 EDT 2003


I have test.cs:
using System;
                                                                                                                                
namespace Test
{
     public class Test
     {
         public String test ()
         {
		return DateTime.Now.ToString()
         }
     }
}


and test.c
#include <mono/jit/jit.h>
#include <mono/metadata/debug-helpers.h>
                                                                                                                                
char* process()
{
     MonoDomain *domain;
     MonoAssembly *assembly;
     MonoClass *class;
     MonoMethod *method;
     MonoMethodDesc *desc;
     MonoObject *mono_ret, *exception = NULL;
     gpointer arguments [4];
                                                                                                                                    
domain = mono_jit_init ("test");
     assembly = mono_domain_assembly_open (domain, "test.dll");
     if (!assembly) {
         fprintf (stderr, "Assembly not loaded\n");
         mono_jit_cleanup (domain);
         return NULL;
     }
                                                                                                                                    
class = mono_class_from_name (assembly->image, "Test", "Test");
     if (!class) {
         fprintf (stderr, "Class not loaded\n");
         mono_jit_cleanup (domain);
         return NULL;
     }
                                                                                                                                    
desc = mono_method_desc_new (":test()", 0);
                                                                                                                                    
method = mono_method_desc_search_in_class (desc, class);
     if (!method) {
         fprintf (stderr, "Method Desc not loaded\n");
         return NULL;
     }
                                                                                                                                    
mono_ret = mono_runtime_invoke (method, NULL, NULL, NULL);
     fprintf(stderr,"xxx\n");fflush(stderr);
                                                                                                                                    
mono_jit_cleanup (domain);
     return (char *) mono_string_to_utf8((MonoString*) mono_ret);
                                                                                                                                
}
                                                                                                                                
void main () {
     char *s;
                                                                                                                                    
s = process ();
     fprintf(stderr, "%s\n", s);
}

compile both with:
mcs /t:library  test.cs -out:test.dll
and
gcc -o t test.c `PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig pkg-config 
--cflags --libs mono`

when I ran the program:
[mdamt at gordon src]$ ./t
  Unhandled Exception: System.NullReferenceException: A null value was 
found where an object instance was required
in <0x0000f> 00 System.Globalization.DateTimeFormatInfo:get_CurrentInfo 
()
in <0x00066> 00 System.Globalization.DateTimeFormatInfo:GetInstance 
(System.IFormatProvider)
in <0x0002b> 00 System.DateTime:ToString (string,System.IFormatProvider)
in <0x00017> 00 System.DateTime:ToString ()
in <0x00039> 00 Test.Test:test ()

[hangs]

question 1:
What I expect is the program showing DateTime.Now.ToString() string. If 
I change DateTime with something like
"abc".ToString(), it returns and print "abc".
Did I miss something?

question 2:
what is the best method to catch the exception like this without 
hanging?

thanks
-- 
Mohammad DAMT <mdamt at bisnisweb.com>



More information about the Mono-devel-list mailing list