Search code examples
c#clrautofac

System.ExecutionEngineException in DBContext Constructor


I know this is a very vague error, but I've posted on the EF Core and CLR git repositories, and they have no idea. I wonder if this might have something to do with dependency injection (I'm using AutoFac).

The error happens about every other time I start a new debugging session. It happens in the constructor of my class which inherits from DbContext, when I am passing the DbContextOptions down to the base.

Exception:

Exception Type: System.ExecutionEngineException

Exception Message="Exception of type 'System.ExecutionEngineException' was thrown."

Stack trace: Empty

protected WinsDbContextBase(DbContextOptions options, ICurrentUserContext userContext)
    : base(options) <=== the error occurs on this line
    {
... other code here ...
    }

I know this is not really enough to go on, but I'm posting this here in hopes that maybe someone else has experienced this and can give me a clue as to where to start digging.

Edit: This came down to a known bug in the CLR and is scheduled to be fixed in 4.8 framework build. The workaround was to add the following to my Machine.config file:

<configuration>
        <runtime>
          <disableNativeImageLoad>
            <assemblyIdentity name="netstandard" />
          </disableNativeImageLoad>
        </runtime>
    </configuration>

https://github.com/dotnet/coreclr/issues/22137


Solution

  • This came down to a known bug in the CLR and is scheduled to be fixed in 4.8 framework build. The workaround was to add the following to my Machine.config file:

    <configuration>
            <runtime>
              <disableNativeImageLoad>
                <assemblyIdentity name="netstandard" />
              </disableNativeImageLoad>
            </runtime>
        </configuration>
    

    https://github.com/dotnet/coreclr/issues/22137