1iveowl
1iveowl

Reputation: 1732

System.Reflection.MissingRuntimeArtifactException - in release mode

I'm trying to compile UWP app. It runs fine in Debug mode, but when trying to run it in release mode I get this error:

Exception thrown: 'System.Reflection.MissingRuntimeArtifactException' in System.Private.Reflection.Core.dll

Additional information: MakeGenericMethod_NoMetadata, System.Linq.Enumerable.Distinct<System.Int32>(System.Collections.Generic.IEnumerable<System.Int32>).

When breaking in the exception in VS2015 also get this message (still release mode):

ExecutionEnvironment.cs not found

I found a similar issue/solution in SO, but that didn't work in my case: https://stackoverflow.com/a/31548178/4140832

I'm using the UWP SDK 1.1.

UPDATE: I also found this: http://dotnet.github.io/native/troubleshooter/method.html#

... but I'm unsure if this is the answer and unsure how to use the tool based on the information provided above.

UPDATE 2: .NET Native General Troubleshooting: https://msdn.microsoft.com/en-us/library/dn600643(v=vs.110).aspx

Upvotes: 2

Views: 679

Answers (1)

1iveowl
1iveowl

Reputation: 1732

I found a solution. It turned out to be related to the particular combination of AutoMapper and .NET Native. Changing Runtime Directives was a detour in this particular case.

In my code I had a AutoMapper configuration that looks something like this:

Mapper.CreateMap<SomethingGood, ISomething>().As<SomethingBetter>(); 

This works when the app was not compiled to the .NET Native tool chain (i.e. when running in debug mode). However, when compiling for release this AutoMapper code breaks.

Also, in the class SomethingBetter I had more properties defined than what was defined in ISomething and the SomethingGood class. This was a mistake, but it went unnoticed in debug mode. When compiling to .NET Native the App would throw a 'System.Reflection.MissingRuntimeArtifactException'.

To track down this bugs I used the .NET Native debug engine. Without using this it was close to impossible to figure out that was the root cause for the exception.

This blog post explains using the .NET Native debugger very nicely: http://blogs.msdn.com/b/visualstudioalm/archive/2015/07/29/debugging-net-native-windows-universal-apps.aspx

Also, putting this try/catch at the end of all the AutoMapper.Mapper.CreateMap's was very helpful to track down the properties causing the issue:

        try
        {
            AutoMapper.Mapper.AssertConfigurationIsValid();
        }
        catch (Exception ex)
        {

            throw ex;
        }

Upvotes: 0

Related Questions