[Mono-list] Generic class and mono_class_from_name
mimi
zachary.xu at jomediainc.com
Tue Mar 10 19:24:31 UTC 2015
I embedded Mono runtime 3.12 in my QT c++ app on Os x 10.8.5 and try to get
generic class in my c++ app.
Case 1:
c#
namespace TestDictionary
{
public class Class1
{
public Dictionary<string,object> DictionaryField;
public static void Dump (Dictionary <string, object> dictionary)
{
Console.WriteLine("Dump called\n");
}
public static void Main()
{
Console.WriteLine("Class1 Main called!\n");
}
}
}
c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, "TestDictionary",
"Class1");
I compiled TestDictionary.exe and classDictionary is non-NULL.
Case 2:
c#
namespace TestDictionary
{
public class Class1
{
public Dictionary<string,object> DictionaryField;
public static void Dump (Dictionary <string, object> dictionary)
{
Console.WriteLine("Dump called\n");
}
}
}
namespace Playstkop.Toolbox
{
public class ToolboxFacade
{
public static void Main()
{
Class1 testClass1 = new Class1();
Console.WriteLine("ToolboxFacade Main called!!\n");
}
}
}
c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, "TestDictionary",
"Class1");
I compiled TestDictionary.dll and Playstkop.Toolbox.exe. classDictionary
returns NULL. I digged into mono_class_from_name and found that the value of
'name' is 0x0 instead of "Class1".
Locals
assembly_idx @0xffffffffffffffff guint32
buf " \235§\013\001\000\000\000..." char [1024]
class 0x0 MonoClass *
class at 1 0x0 MonoClass *
class at 2 @0x10bca9f00 MonoClass
cols @0x0 guint32 [5]
i @0xffffffffffffffff int
idx @0xffffffffffffffff guint32
image @0x10487fe00 MonoImage
impl @0xffffffffffffffff guint32
len @0xffffffffffffffff int
loaded_image 0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space "TestDictionary" char *
nested 0x0 char *
nspace_table 0x0 GHashTable *
pos @0xffffffffffffffff int
res @0xffffffffffffffff gboolean
t 0x0 MonoTableInfo *
token 0 guint32
This is the Locals when 'mono_class_from_name' returns:
Locals
assembly_idx @0xffffffffffffffff guint32
buf " ݯ\013\001\000\000\000@ú\..." char [1024]
class 0x0 MonoClass *
class at 1 0x0 MonoClass *
class at 2 0x0 MonoClass *
cols @0x0 guint32 [5]
i @0xffffffffffffffff int
idx @0xffffffffffffffff guint32
image 0x0 MonoImage *
impl @0xffffffffffffffff guint32
len @0xffffffffffffffff int
loaded_image 0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space "TestDictionary" char *
nested 0x0 char *
nspace_table 0x0 GHashTable *
pos @0xffffffffffffffff int
res @0xffffffffffffffff gboolean
t 0x0 MonoTableInfo *
token 0 guint32
I go back to Case 1 and trace the method 'mono_class_from_name'. The value
of 'name' is also 0x0 (Surprised!).
Locals
assembly_idx @0xffffffffffffffff guint32
buf " ý§\013\001\000\000 at ..." char [1024]
class 0x0 MonoClass *
class at 1 0x0 MonoClass *
class at 2 @0x10bcaff00 MonoClass
cols @0x0 guint32 [5]
i @0xffffffffffffffff int
idx @0xffffffffffffffff guint32
image @0x1068a3c00 MonoImage
impl @0xffffffffffffffff guint32
len @0xffffffffffffffff int
loaded_image 0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space "TestDictionary" char *
nested 0x0 char *
nspace_table 0x0 GHashTable *
pos @0xffffffffffffffff int
res @0xffffffffffffffff gboolean
t 0x0 MonoTableInfo *
token 0 guint32
However, when 'mono_class_from_name' returns, Class1 is returned.
Locals
assembly_idx @0xffffffffffffffff guint32
buf " \035\227\013\001\000\..." char [1024]
class 0x0 MonoClass *
class at 1 0x0 MonoClass *
class at 2 @0x10ac90e10 MonoClass
blittable 167774213 guint:1
byval_arg @0x10ac90ed8 MonoType
cast_class @0x10ac90e10 MonoClass
contextbound 7408128 guint:1
delegate 28938 guint:1
element_class @0x10ac90e10 MonoClass
enumtype 167774213 guint:1
exception_type '\0' guint8
ext 0x0 MonoClassExt *
field @0x10ac90e98 _MonoClass::<anonymous struct>
fields @0x10ac92090 MonoClassField
fields_inited 113 guint:1
flags 1048577 guint32
gc_descr (NSAtom *) gc_descr = 0x2000000000000001 void *
gc_descr_inited 28938 guint:1
generic_class 0x0 MonoGenericClass *
generic_container 0x0 MonoGenericContainer *
ghcimpl 7408128 guint:1
has_cctor 28938 guint:1
has_finalize 7408128 guint:1
has_finalize_inited 113 guint:1
has_references 28938 guint:1
has_static_refs 28938 guint:1
idepth 2 guint16
image @0x1048e0400 MonoImage
init_pending 167774213 guint:1
inited 167774213 guint:1
instance_size 24 int
interface_bitmap '\0' guint8
interface_count 0 guint16
interface_id 0 guint16
interface_offsets_count 0 guint16
interface_offsets_packed 0 guint16
interfaces 0x0 MonoClass **
interfaces_inited 113 guint:1
interfaces_packed 0x0 MonoClass *
is_com_object 28938 guint:1
is_generic 113 guint:1
is_inflated 113 guint:1
marshal_info 0x0 MonoMarshalType *
marshalbyref 7408128 guint:1
max_interface_id 0 guint16
method @0x10ac90ea0 _MonoClass::<anonymous struct>
count 3 guint32
first 0 guint32
methods 0x0 MonoMethod **
min_align '\8' guint8
name "Class1" char *
name_space "TestDictionary" char *
nested_classes_inited 28938 guint:1
nested_in 0x0 MonoClass *
next_class_cache 0x0 MonoClass *
no_special_static_fields 28938 guint:1
packing_size 7408128 guint:4
parent @0x10ac66280 MonoClass
rank '\0' guint8
ref_info_handle 0 guint32
runtime_info @0x10ac92100 MonoClassRuntimeInfo
setup_fields_called 113 guint:1
simd_type 113 guint:1
size_inited 167774213 guint:1
sizes @0x10ac90e90 _MonoClass::<anonymous union>
supertypes @0x10ac66280 MonoClass
this_arg @0x10ac90ec8 MonoType
type_token 33554434 guint32
unicode 167774213 guint:1
valuetype 167774213 guint:1
vtable @0x1048d7818 MonoMethod
vtable_size 4 int
wastypebuilder 167774213 guint:1
cols @0x0 guint32 [5]
i @0xffffffffffffffff int
idx @0xffffffffffffffff guint32
image 0x0 MonoImage *
impl @0xffffffffffffffff guint32
len @0xffffffffffffffff int
loaded_image 0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space "TestDictionary" char *
nested 0x0 char *
nspace_table 0x0 GHashTable *
pos @0xffffffffffffffff int
res @0xffffffffffffffff gboolean
t 0x0 MonoTableInfo *
token @0xffffffffffffffff guint32
Here I did something wrong or understood wrong? Any advice helps. Thanks!
--
View this message in context: http://mono.1490590.n4.nabble.com/Generic-class-and-mono-class-from-name-tp4665611.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list