Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting "Invalid Internal state" reflection exception with Castle DynamicProxy?
    primarykey
    data
    text
    <p>We added DynamicProxy to our ASP.NET web app a couple of weeks ago. The code ran fine in dev and QA, but when we pushed to production, we got the following exception (top of stack trace only):</p> <pre><code>[ArgumentNullException: Invalid internal state.] </code></pre> <p>System.Reflection.Emit.TypeBuilder._InternalSetMethodIL(Int32 methodHandle, Boolean isInitLocals, Byte[] body, Byte[] LocalSig, Int32 sigLength, Int32 maxStackSize, Int32 numExceptions, __ExceptionInstance[] exceptions, Int32[] tokenFixups, Int32[] rvaFixups, Module module) +0 System.Reflection.Emit.TypeBuilder.InternalSetMethodIL(Int32 methodHandle, Boolean isInitLocals, Byte[] body, Byte[] LocalSig, Int32 sigLength, Int32 maxStackSize, Int32 numExceptions, __ExceptionInstance[] exceptions, Int32[] tokenFixups, Int32[] rvaFixups, Module module) +56 System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() +1033 System.Reflection.Emit.TypeBuilder.CreateType() +99 Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type) +72 Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType() +96 Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope) +854 Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options) +834 Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) +133 Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) +52 Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) +308 Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) +48 Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) +44</p> <p>It worked fine when we first pushed the code, and an IIS reset fixed it, so I'm assuming it's thread related, but I couldn't find anything on the interwebs regarding best practices for thread-safety proxy generation. Suggestions?</p> <p>UPDATE: After reading some more on the issue, especially <a href="http://kozmic.pl/archive/2009/10/30/castle-dynamic-proxy-tutorial-part-xv-patterns-and-antipatterns.aspx" rel="nofollow noreferrer">here</a>, I realized one potential issue -- namely that I had not overwritten Equals/GetHashCode for the implementation of IProxyGenerationHook I had written, which would prevent DynamicProxy from caching it's types. As I can find next to nothing on the exception I saw in general let alone related to DP, I'm gonna assume that it was the lack of caching of types caused by my omission that was the root cause of the problem, though I'd love a confirmation.</p> <p>For the record, my object creation is pretty vanilla:</p> <pre><code>private T CreateProxy(MyArgs args) { var options = new ProxyGenerationOptions(new MyMethodSelector()); options.AddMixinInstance(new MyMixin()); return Generator.CreateClassProxy( TargetType, options, new[] { new MyInterceptor(args) }) as T; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload