I am trying to resolve a TimeSpan using Unity. Executing the container Resolve call results in a FatalExecutionEngineError.
FatalExecutionEngineError was detected Message: The runtime has encountered a fatal error. The address of the error was at 0x543c3dc8, on thread 0x1bb8. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Running the test in DEBUG causes the following file to be requested by the debugger.
X:\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs
And it shows the following ExecutionEngineException on line 38.
System.ExecutionEngineException was unhandled Message="Exception of type 'System.ExecutionEngineException' was thrown." InnerException:
Test
[TestClass]
public class Example
{
private readonly IUnityContainer container = new UnityContainer();
[TestInitialize]
public void TestInitialize()
{
container.Register<TimeSpan>(new ExternallyControlledLifetimeManager());
}
[TestMethod]
public void Test()
{
var expected = new TimeSpan();
var actual = container.Resolve<TimeSpan>();
Assert.AreEqual(expected, actual);
}
}