Problem with Assembly.CreateInstance

  • Thread starter Thread starter CoffeeMug
  • Start date Start date
C

CoffeeMug

When I execute the following code from ASP.NET my application
sporadically hangs inside CreateInstance(). The hangs don't occur every
time but are frequent enough to be considered a serious problem.

Assembly asm = Assembly.GetAssembly(typeof(MyType));
Type t = asm.GetType("MyType2");
object obj = asm.CreateInstance("MyType2");

MyType as well as MyType2 are C# wrappers for native C functions. I
also noticed that methods of these wrappers (that PInvoke native code)
randomly throw NullReferenceException and CreateInstance hangs in
subsequent calls to the page. The problem is tricky to debug since I
can't figure out exact circumstances of the crashes. If anyone could
point me to suggestions or ideas, it'd be great.

Thanks.
 
CoffeeMug said:
When I execute the following code from ASP.NET my application
sporadically hangs inside CreateInstance(). The hangs don't occur every
time but are frequent enough to be considered a serious problem.

Assembly asm = Assembly.GetAssembly(typeof(MyType));
Type t = asm.GetType("MyType2");
object obj = asm.CreateInstance("MyType2");

MyType as well as MyType2 are C# wrappers for native C functions. I
also noticed that methods of these wrappers (that PInvoke native code)
randomly throw NullReferenceException and CreateInstance hangs in
subsequent calls to the page. The problem is tricky to debug since I
can't figure out exact circumstances of the crashes. If anyone could
point me to suggestions or ideas, it'd be great.

you may try this more straightforward code:

object o = Activator.CreateInstance(typeof(MyType));

bye
Rob
 
you may try this more straightforward code:

object o = Activator.CreateInstance(typeof(MyType));

Anywhere you can do that, you should also be able to just do

object o = new MyType();



Mattias
 
Make sure that you can instantiate them without the CreateInstance() calls.
i.e. As someone suggested, try new. If that works. then investigate the
CreateInstance().
Beyond that, How were these wrappers written?
 
Back
Top