Tuesday, October 16, 2012

FIXED: "Invalid type owner for DynamicMethod" error in Nhibernate

If you recieve the "Invalid type owner for DynamicMethod" error while initializing you NHibernate SessionFactory then it's pretty likely that you are using generic methods on some of your lazy loaded/proxied classes.

Nhibernate incorporates a reflection optimization that speeds up the creation of proxy classes. This reflection optimization does not play well with generics. The error it throws is "Invalid type owner for DynamicMethod". Not very friendly.

So, to fix this you must either stop using generic methods OR turn off the optimization. To turn off the optimization you must run the following code before you initialize your SessionFactory.

NHibernate.Cfg.Environment.UseReflectionOptimizer = false;

1 comment:

Dreami Tom said...

Its really an informative submit for the readers who facing such a problem of "Invalid type owner for DynamicMethod" and getting very effective solution for it. Actually I was going to write an essay paper for my education. And will it be helpful my education. Lets ask with dissertation writing service and they will help to write about any kind of informative topic.