AssemblyGen assembly = new AssemblyGen("Test.dll", true);
TypeGen testClass = assembly.Public.Class("TestClass", typeof(object));
testClass.Static.Private.Field(typeof(string), "dName", "my name");
assembly.Complete();
Type type = testClass.GetCompletedType(true);
object obj = Activator.CreateInstance(type);
// when try to create an object of type, it throw exception. Look deep into the
exception, it is "The type initializer for 'TestClass' threw an exception." and
"Attempted to read or write protected memory. This is often an indication that
other memory is corrupt.", "at Test.Dynamic.TestClass..cctor()"
// even I added the following two lines before calling
testClass.Static.Private.Field(typeof(string), "dName", "my name"), the result
is the same
ConstructorGen staticConstructor = testClass.Static.Constructor();
ConstructorGen instanceConstructor = testClass.Public.Constructor();
But, if don't assign the initial value "my name" to that static field, it works
fine.
Original issue reported on code.google.com by lz...@tcet.com on 11 Jan 2013 at 9:32
Original issue reported on code.google.com by
lz...@tcet.com
on 11 Jan 2013 at 9:32