This project is read-only.

problems with simpleinjector and VS2013

Aug 14, 2014 at 2:43 PM
I am having problems using simpleinjector in VS2013. The most extreme example of it not working can be demonstrated with this snippet:

using System;
using SimpleInjector;

namespace ConsoleApplication6
{
class Program
{
    static void Main(string[] args)
    {
        var container = new Container();
        container.Verify();

        Console.WriteLine("done");
        Console.ReadLine();
    }
}
}


When I run it i get the following error:



System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The configuration is invalid. Creating the instance for type Container failed. The registered delegate for type Container threw an exception. Error occurred while trying to build a delegate for type Container using the expression "value(SimpleInjector.Container)". JIT Compiler encountered an internal limitation.
Source=SimpleInjector
StackTrace:
   at SimpleInjector.InstanceProducer.VerifyInstanceCreation()
   at SimpleInjector.Container.VerifyInstanceCreation(InstanceProducer[] producersToVerify)
   at SimpleInjector.Container.VerifyIfAllRootObjectsCanBeCreated()
   at SimpleInjector.Container.Verify()
   at ConsoleApplication6.Program.Main(String[] args) in d:\Users\Stefan\Documents\Visual Studio 2013\Projects\ConsoleApplication6\ConsoleApplication6\Program.cs:line 11
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: SimpleInjector.ActivationException
   HResult=-2146233088
   Message=The registered delegate for type Container threw an exception. Error occurred while trying to build a delegate for type Container using the expression "value(SimpleInjector.Container)". JIT Compiler encountered an internal limitation.
   Source=SimpleInjector
   StackTrace:
        at SimpleInjector.InstanceProducer.GetInstance()
        at SimpleInjector.InstanceProducer.VerifyInstanceCreation()
   InnerException: SimpleInjector.ActivationException
        HResult=-2146233088
        Message=Error occurred while trying to build a delegate for type Container using the expression "value(SimpleInjector.Container)". JIT Compiler encountered an internal limitation.
        Source=SimpleInjector
        StackTrace:
             at SimpleInjector.InstanceProducer.BuildInstanceCreator()
             at SimpleInjector.InstanceProducer.GetInstance()
        InnerException: System.InvalidProgramException
             HResult=-2146233030
             Message=JIT Compiler encountered an internal limitation.
             Source=SimpleInjector
             StackTrace:
                  at SimpleInjector.CompilationHelpers.CompileExpression[TResult](Container container, Expression expression)
                  at SimpleInjector.InstanceProducer.BuildInstanceCreator()
             InnerException: 

If I run without debugging or run the same code in VS2012 it works fine.

Any ideas? I tried running a repair on visual studio and did not help. Anything else I can try?

I am using simple injector 2.5.2.0 from nuget.
Aug 14, 2014 at 2:50 PM
After racking my brain for 3 hours today, I solved almost immediately after posting this in desperation....

The issue was that I had Intellitrace set to collect events AND call information. When I moved it back to events only everything started running smoothly again.

Might still be something worth looking at?
Aug 14, 2014 at 3:35 PM
Great that you found the problem. This issue has been reported before but we weren't able to pin point it to a specific source, which you may now have found. Unfortunately, I'm not sure that there actually is anything that Simple Injector can do about this. It really seems a bug in IntelliTrace. But we might be able to register a bug report for this on the Microsoft Connect website.

In the meantime, if you really need that "call information" option of IntelliTrace, you can set the following configuration option, and everything will work smoothly:
container.Options.EnableDynamicAssemblyCompilation = false;