Twitter LinkedIn Github


I just upgraded to the latest release of StructureMap (2.5) and spent a good portion of time trying to figure out a bug I was having in a complex dependency graph. The original exception is a StructureMap exception, with code 207, which per documentation, you need to look at the inner exception. The problem is that the inner exception isn't awfully helpful:


System.InvalidProgramException : JIT Compiler encountered an internal limitation.

Initially I thought it was related to the WithCtorArg method that allows you to pass in parameters to the constructor, but after stripping everything down to try and come up with a test case, it seems that the issue occurs when you have a class that the container resolves which has a public static property, like so:

   1: public interface ISomeClass
   2: {
   3:     void SomeMethod();
   4: }
   6: public class SomeClass : ISomeClass
   7: {
   9:     public static int SomeProperty { get; set; }
  11:     public void SomeMethod()
  12:     {
  13:     }
  16: }


Here's the StructureMap configuration test:

   1: [Fact]
   2: public void TestStructureMap()
   3: {
   4:     ObjectFactory.Initialize( x => x.ForRequestedType<ISomeClass>().TheDefault.Is.OfConcreteType<SomeClass>());
   6:     ObjectFactory.GetInstance<ISomeClass>();
   7: }


As soon as you make the property private or make it an instance property, the container resolves fine. I tested the same thing with Unity and there doesn't seem to be an issue.

I tested the same code with 2.4.9 and it seems to work.