Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automapper fails when using .NET Native #901

Closed
nelsonghezzi opened this issue Sep 21, 2015 · 33 comments
Closed

Automapper fails when using .NET Native #901

nelsonghezzi opened this issue Sep 21, 2015 · 33 comments

Comments

@nelsonghezzi
Copy link

Running a UWP project compiled with .NET Native tool chain causes automapper fail with the following exception:

Exception thrown: 'System.Reflection.MissingRuntimeArtifactException' in System.Private.Reflection.Core.dll
Additional information: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.SingleOrDefault<System.Char>(System.Collections.Generic.IEnumerable<System.Char>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868

As far I saw in the call stack, the exception was produced in the method BuildPublicNoArgExtensionMethods.

Reading some of the documentation regarding .NET Native and reflection (APIs That Rely on Reflection), it states that you must supply a specific runtime directive when using MakeGenericMethod, but it hasn't working on my side.

I wonder if this is an issue that automapper can solve by itself by defining its own .rd.xml file, or if exists another workaround that I can use to avoid this error.

Cheers.

@jbogard
Copy link
Member

jbogard commented Sep 21, 2015

Is there an easy way to reproduce this on my side?

@nelsonghezzi
Copy link
Author

I've succeeded in creating a very little project in which the error triggers. It is uploaded in this repo.

Run the app in Release | x86 and you should get an error like this when stepping through the mapping defined in the Profile:

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

Additional information: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.Distinct<System.Char>(System.Collections.Generic.IEnumerable<System.Char>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868

Not exactly the same error as the stated in my original comment, but sure both are highly related. Note that there are two properties in the mapping's destination class which are key in making the error happen.

Environment info:

  • I'm using the tools for Universal Windows Apps v1.1 released last week.
  • I was using Automapper 3.3.1, mostly because this issue has prevented me from upgrading, but I've checked in the sample project, and the error also occurs in 4.0.4.

Hope this points you into the right direction!

@pamtaro
Copy link

pamtaro commented Sep 24, 2015

I'm also having this issue related to AutoMapper and the .NET Native tool chain.

Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.CoreLib.dll
Additional information: Reflection_InsufficientMetadata_EdbNeeded: AutoMapper.Mappers.CollectionMapper.EnumerableMapper<System.Collections.Generic.List<MyViewModel>,MyViewModel>

I've tried following the instructions mentioned in this article to handle the MissingMetadataException, but I'm not sure if I'm writing the correct directives, or if its something my app can't handle and must be added on the Automapper side - http://blogs.msdn.com/b/dotnet/archive/2014/05/21/net-native-deep-dive-help-i-hit-a-missingmetadataexception.aspx

@JamesNK
Copy link

JamesNK commented Oct 6, 2015

Also getting this error.

I had to do this:

    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="ToArray" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Distinct" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Char" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Char" Dynamic="Required"/>
    </Type>

I don't know why all the public no arg extension methods need MakeGenericMethod called on them but making the calls lazy instead of doing it all up front would be a good first step. It would probably help performance and memory usage as well.

@jbogard
Copy link
Member

jbogard commented Oct 6, 2015

@JamesNK Are you kidding me?!?

@Xiard
Copy link

Xiard commented Oct 18, 2015

I'm having a very similar issue:

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

I tried downloading the latest (~4.1.0-ci1033, I guess?) and debugging directly by adding Automapper.WinRT to my solution and referencing it. I turned on native tool chain debugging, and mixed native/managed debugging. When I did that I couldn't run at all; I got a "dependent dll not found" error. I'm guessing that might be because I was AutoMapper WinRT is a Windows 8.1 project rather than UWP, but I'm not sure. Regardless, that didn't help me debug the situation.

I tried putting in directives similar to what JamesNK did above, but for System.Int32 instead of System.Char. This is my first time trying to use a runtime directive file, so I'm not entirely sure where it should go. The code that throws this exception is in a satellite assembly of mine, SightAndSay.DAL.dll. It's the code that sets up the mappings (Mapper.CreateMap). I'm not sure if that means I need to put the runtime directive file in that assembly or if it should go in a section in the main app's *.rd.xml file.

So far I've tried the following:

SightAndSay.rd.xml (in the main application's folder):

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <Assembly Name="*Application*" Dynamic="Required All" />

    <!-- Add your application specific runtime directives here. -->
    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="Distinct" Arguments="System.Int32" Dynamic="Required" />
      <MethodInstantiation Name="ToArray" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Int32" Dynamic="Required"/>
    </Type>

  </Application>

  <Library Name="SightAndSay.DAL">
    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="Distinct" Arguments="System.Int32" Dynamic="Required" />
      <MethodInstantiation Name="ToArray" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Int32" Dynamic="Required"/>
    </Type>
  </Library>
</Directives>

SightAndSayDAL.rd.xml (in the SightAndSay.DAL.dll project's folder):

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <Assembly Name="*Application*" Dynamic="Required All" />

    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="Distinct" Arguments="System.Int32" Dynamic="Required" />
      <MethodInstantiation Name="ToArray" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Int32" Dynamic="Required"/>
    </Type>
  </Application>

  <Library Name="SightAndSay.DAL">
    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="Distinct" Arguments="System.Int32" Dynamic="Required" />
      <MethodInstantiation Name="ToArray" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Int32" Dynamic="Required"/>
    </Type>
  </Library>
</Directives>

So far I'm still getting the exception. At the moment that means I'm dead in the water for submitting my app to the store, unfortunately.

Here are some links I found helpful:

https://msdn.microsoft.com/en-us/library/dn600634%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

https://msdn.microsoft.com/en-us/library/dn600165(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dn600639(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dn798709(v=vs.110).aspx

Please let me know if there's anything I can do to help debug this.

@Xiard
Copy link

Xiard commented Oct 18, 2015

I just realized that I have a Default.rd.xml file in my Properties folders. I tried moving the block above into both the application's Default.rd.xml file and the assembly's Default.rd.xml file. That didn't help.

I also tried putting the following directive in both places instead of the directive:

<Namespace Name="System.Linq" Dynamic="Required All" Serialize="Required All" XmlSerializer="Required All" />

The exception is still being thrown.

@Xiard
Copy link

Xiard commented Oct 18, 2015

Here's another article that provides some useful information for library writers: http://blogs.msdn.com/b/dotnet/archive/2014/05/21/net-native-deep-dive-help-i-hit-a-missingmetadataexception.aspx . It makes it sound like changing the AutoMapper rd.xml file may be the "right" solution.

@Xiard
Copy link

Xiard commented Oct 18, 2015

Here's a bit of information about my latest failed attempt to resolve this. I created a Universal class library in my solution and added all of the automapper files to my project (Xiard.Automapper). Those are the L&G files from github. I uninstalled the AutoMapper package from all of my projects that were using it and referenced Xiard.AutoMapper instead. I modified the default Xiard.AutoMapper.rd.xml file in the Xiard.AutoMapper\Properties folder to include all of the following directives. This should be extreme overkill, but based on the error I would have thought this would resolve the issue:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Library Name="Xiard.AutoMapper">
    <Assembly Name="System.Linq" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All" />
    <Namespace Name="System.Collections.Generic" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All" />
    <Namespace Name="System.Linq" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All" />
    <Namespace Name="System.Linq.Enumerable" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All"  />
    <Namespace Name="AutoMapper" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All"  />
    <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
      <MethodInstantiation Name="Distinct" Arguments="System.Int32" Dynamic="Required" />
      <MethodInstantiation Name="ToArray" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Reverse" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="AsEnumerable" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="ToList" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="First" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="FirstOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Last" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LastOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Single" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="SingleOrDefault" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Any" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Count" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="LongCount" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Min" Arguments="System.Int32" Dynamic="Required"/>
      <MethodInstantiation Name="Max" Arguments="System.Int32" Dynamic="Required"/>
    </Type>
  </Library>
</Directives>

I then realized I was getting warnings about System.Linq.Enumerable being ambiguous between System.Xml and System.Linq, so I modified my rd.xml files to simply have:

    <Assembly Name="System.Linq" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All" />

No luck. Same error in release mode. However, I did fix another issue (referencing the wrong VCLibs to use with SQLite UAP), and that got me running in debug mode. Same error. But that now allows me to at least get a stack trace when the exception occurs:

System.Reflection.MissingRuntimeArtifactException: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.Distinct<System.Int32>(System.Collections.Generic.IEnumerable<System.Int32>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868
   at SightAndSay!<BaseAddress>+0x353da2f
   at SightAndSay!<BaseAddress>+0x354fdde
   at SightAndSay!<BaseAddress>+0x354e6b1
   at SightAndSay!<BaseAddress>+0x354e5be
   at AutoMapper.TypeInfo.<>c__DisplayClass21_1.<BuildPublicNoArgExtensionMethods>b__6(Type t)
   at System.Func<System.Object,System.Boolean>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1e7b4cf
   at AutoMapper.TypeInfo.<>c__DisplayClass21_0.<BuildPublicNoArgExtensionMethods>b__4(Reflection.MethodInfo,System.Type> <>h__TransparentIdentifier0)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x198bcb1
   at SightAndSay!<BaseAddress>+0x198bcf6
   at System.Collections.Generic.List<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>>.InsertRange(Int32 index, Collections.Generic.IEnumerable<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>> collection)
   at System.Collections.Generic.List<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>>.AddRange(Collections.Generic.IEnumerable<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>> collection)
   at AutoMapper.TypeInfo.BuildPublicNoArgExtensionMethods(Collections.Generic.IEnumerable<System.Reflection.MethodInfo> sourceExtensionMethodSearch)
   at AutoMapper.TypeInfo..ctor(Type type, Func<System.Reflection.PropertyInfo,System.Boolean> shouldMapProperty, Func<System.Reflection.FieldInfo,System.Boolean> shouldMapField, Collections.Generic.IEnumerable<System.Reflection.MethodInfo> sourceExtensionMethodSearch)
   at AutoMapper.TypeMapFactory.<>c__DisplayClass4_0.<GetTypeInfo>b__0(Type t)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1bae9f4
   at AutoMapper.Internal.DictionaryFactoryOverride.ConcurrentDictionaryImpl<System.Object,System.Object>.GetOrAdd(Object key, Func<System.Object,System.Object> valueFactory)
   at AutoMapper.TypeMapFactory.GetTypeInfo(Type type, Func<System.Reflection.PropertyInfo,System.Boolean> shouldMapProperty, Func<System.Reflection.FieldInfo,System.Boolean> shouldMapField, Collections.Generic.IEnumerable<System.Reflection.MethodInfo> extensionMethodsToSearch)
   at AutoMapper.TypeMapFactory.GetTypeInfo(Type type, IMappingOptions mappingOptions)
   at AutoMapper.TypeMapFactory.MapDestinationPropertyToSource(Collections.Generic.LinkedList<System.Reflection.MemberInfo> resolvers, TypeInfo sourceType, String nameToSearch, IMappingOptions mappingOptions)
   at AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options, MemberList memberList)
   at AutoMapper.ConfigurationStore.<>c__DisplayClass83_0.<CreateTypeMap>b__0(Impl.TypePair tp)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1bae9f4
   at AutoMapper.Internal.DictionaryFactoryOverride.ConcurrentDictionaryImpl<System.Object,System.Object>.GetOrAdd(Object key, Func<System.Object,System.Object> valueFactory)
   at AutoMapper.ConfigurationStore.CreateTypeMap(Type source, Type destination, String profileName, MemberList memberList)
   at SightAndSay!<BaseAddress>+0x23927f7
   at SightAndSay!<BaseAddress>+0x2396626
   at SightAndSay!<BaseAddress>+0x23965a4
   at SightAndSay!<BaseAddress>+0x260a935
   at SightAndSay.DAL.DTO.DTOManager.InitializeMappings()
Exception thrown: 'System.Reflection.MissingRuntimeArtifactException' in SightAndSay.DAL.dll
An exception of type 'System.Reflection.MissingRuntimeArtifactException' occurred in SightAndSay.DAL.dll but was not handled in user code
Additional information: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.Distinct<System.Int32>(System.Collections.Generic.IEnumerable<System.Int32>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868

And that is happening on a call to Mapper.CreateMap on a particular class of mine, not on every class. I will see if I can dig into that a little deeper, now that I can debug directly.

@Xiard
Copy link

Xiard commented Oct 18, 2015

I think I can safely say that the issue has something to do with enum values. I've created these bogus classes in my app:

public enum TestEnum { Val1, Val2 }

public class TestClassDTO {
    public int TestValue { get; set; }
}

public class TestClass {
    public int TestValue { get; set; }

    [Ignore, AutoMapper.IgnoreMap]
    public TestEnum TestValueEnum {
        get { return (TestEnum) TestValue; }
        set { TestValue = (int) value; }
    }
}

The exception happens when I call:

Mapper.CreateMap<TestClassDTO, TestClass>();

I think that's as far as I'm going to go on my side. I don't know why the runtime directives aren't helping, but clearly they're not. So I'm going to rewrite my code to remove the enum helper properties. I'll keep an eye on this post in case you come up with something that allows me to put them back.

@Xiard
Copy link

Xiard commented Oct 19, 2015

Scratch that. I just figured out that the issue appears to be ignored properties, not enum properties. So this code also causes the problem to appear:

    public class TestClassDTO {
        public string TestString { get; set; }
    }

    public class TestClass  {
        public string TestString { get; set; }

        [IgnoreMap]
        public string TestStringIgnored { get; set; }
    }

When I switched to strings instead of ints for the test, the exception changed slightly:

System.Reflection.MissingRuntimeArtifactException: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.Distinct<System.Char>(System.Collections.Generic.IEnumerable<System.Char>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868
   at SightAndSay!<BaseAddress>+0x354811f
   at SightAndSay!<BaseAddress>+0x355a4ce
   at SightAndSay!<BaseAddress>+0x3558da1
   at SightAndSay!<BaseAddress>+0x3558cae
   at AutoMapper.TypeInfo.<>c__DisplayClass21_1.<BuildPublicNoArgExtensionMethods>b__6(Type t)
   at System.Func<System.Object,System.Boolean>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1e834cf
   at AutoMapper.TypeInfo.<>c__DisplayClass21_0.<BuildPublicNoArgExtensionMethods>b__4(Reflection.MethodInfo,System.Type> <>h__TransparentIdentifier0)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1993cb1
   at SightAndSay!<BaseAddress>+0x1993cf6
   at System.Collections.Generic.List<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>>.InsertRange(Int32 index, Collections.Generic.IEnumerable<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>> collection)
   at System.Collections.Generic.List<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>>.AddRange(Collections.Generic.IEnumerable<System.Action<System.Data.Services.Client.MessageReaderSettingsArgs>> collection)
   at AutoMapper.TypeInfo.BuildPublicNoArgExtensionMethods(Collections.Generic.IEnumerable<System.Reflection.MethodInfo> sourceExtensionMethodSearch)
   at AutoMapper.TypeInfo..ctor(Type type, Func<System.Reflection.PropertyInfo,System.Boolean> shouldMapProperty, Func<System.Reflection.FieldInfo,System.Boolean> shouldMapField, Collections.Generic.IEnumerable<System.Reflection.MethodInfo> sourceExtensionMethodSearch)
   at AutoMapper.TypeMapFactory.<>c__DisplayClass4_0.<GetTypeInfo>b__0(Type t)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1bb69f4
   at AutoMapper.Internal.DictionaryFactoryOverride.ConcurrentDictionaryImpl<System.Object,System.Object>.GetOrAdd(Object key, Func<System.Object,System.Object> valueFactory)
   at AutoMapper.TypeMapFactory.GetTypeInfo(Type type, Func<System.Reflection.PropertyInfo,System.Boolean> shouldMapProperty, Func<System.Reflection.FieldInfo,System.Boolean> shouldMapField, Collections.Generic.IEnumerable<System.Reflection.MethodInfo> extensionMethodsToSearch)
   at AutoMapper.TypeMapFactory.GetTypeInfo(Type type, IMappingOptions mappingOptions)
   at AutoMapper.TypeMapFactory.MapDestinationPropertyToSource(Collections.Generic.LinkedList<System.Reflection.MemberInfo> resolvers, TypeInfo sourceType, String nameToSearch, IMappingOptions mappingOptions)
   at AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options, MemberList memberList)
   at AutoMapper.ConfigurationStore.<>c__DisplayClass83_0.<CreateTypeMap>b__0(Impl.TypePair tp)
   at System.Func<System.Object,System.Object>.Invoke(Object arg)
   at SightAndSay!<BaseAddress>+0x1bb69f4
   at AutoMapper.Internal.DictionaryFactoryOverride.ConcurrentDictionaryImpl<System.Object,System.Object>.GetOrAdd(Object key, Func<System.Object,System.Object> valueFactory)
   at AutoMapper.ConfigurationStore.CreateTypeMap(Type source, Type destination, String profileName, MemberList memberList)
   at SightAndSay!<BaseAddress>+0x239a747
   at SightAndSay!<BaseAddress>+0x239e576
   at SightAndSay!<BaseAddress>+0x239e4f4
   at SightAndSay!<BaseAddress>+0x26123e5
   at SightAndSay.DAL.DTO.DTOManager.InitializeMappings()
Exception thrown: 'System.Reflection.MissingRuntimeArtifactException' in SightAndSay.DAL.dll
An exception of type 'System.Reflection.MissingRuntimeArtifactException' occurred in SightAndSay.DAL.dll but was not handled in user code
Additional information: MakeGenericMethod() cannot create this generic method instantiation because the instantiation was not metadata-enabled: 'System.Linq.Enumerable.Distinct<System.Char>(System.Collections.Generic.IEnumerable<System.Char>)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616868

@Xiard
Copy link

Xiard commented Oct 19, 2015

Also, it appears that the setter is required. This does not trigger the error:

public class TestClassDTO {
    public string TestString { get; set; }
}

public class TestClass  {
    public string TestString { get; set; }

    [IgnoreMap]
    public string TestStringIgnored { get; }
}

@jbogard
Copy link
Member

jbogard commented Oct 19, 2015

Are you using the pre-release version by chance?

@Xiard
Copy link

Xiard commented Oct 19, 2015

Sorry, yes, I thought I made that clear. Should be around 4.1.0-ci1033. I just pulled the L&G code from the "download as zip" link on the GitHub home page.

@jbogard
Copy link
Member

jbogard commented Oct 19, 2015

Great, there was a bug around that version and WinRT/UWP. If you get this to work, I'd love to incorporate this back.

Also, I know that in Silverlight, private anything doesn't work. Maybe this is similar?

@Xiard
Copy link

Xiard commented Oct 19, 2015

So far I'm just punting and getting rid of code that makes AutoMapper choke in release. At the moment I don't think I understand UWP native code or AutoMapper well enough to make even an educated guess about how to go about fixing it. I thought a runtime directive would resolve it, and clearly I was wrong about that.

@jbogard
Copy link
Member

jbogard commented Oct 19, 2015

How are you testing this? I can try some things on my side as well.

@Xiard
Copy link

Xiard commented Oct 19, 2015

I have a fairly large app I'm working on publishing. Main exe plus 19 assemblies. I'm in debug mode with native tool chain turned on, and mixed (managed/native) debugging turned on. I could try to make a standalone simple app to repro it if necessary.

@jbogard
Copy link
Member

jbogard commented Oct 19, 2015

There was a comment earlier on a repro, but was curious, you're not deploying to a device, right? Just debugging out of VS?

@Xiard
Copy link

Xiard commented Oct 19, 2015

That's correct. No deployment, just a straight F5 out of VS. And I assume you saw that I built a UWP class lib version of AutoMapper and added it to my solution rather than using the package on MyGet?

@jbogard
Copy link
Member

jbogard commented Oct 19, 2015

Yep, though what's the reason why there, just for that XML file? AutoMapper supports UWP in the MyGet version (allegedly)

@Xiard
Copy link

Xiard commented Oct 19, 2015

Yes, exactly. I wanted to see if I could workaround the issue by modifying AutoMapper's rd.xml file. I thought that perhaps that's where the runtime directives needed to go. Since that didn't work, either I'm doing the runtime directives incorrectly or this particular problem can't actually be worked around that way. I suspect the former, but I have no idea at the moment.

I will say that I had a similar issue with missing metadata in my own code, and I was able to successfully add a runtime directive in that case. So they are working for me in general; I just couldn't get them to work for this AutoMapper exception.

At this point I have refactored my code to remove all setters from properties with the IgnoreMap attribute. Once I did that, I went back to using the AutoMapper 4.1.0-ci1033 pre-release version. That is working for me in both release and debug now. And, btw, my code passed the Windows App Cert Kit tests as well. So yes, the MyGet version appears to support UWP as far as I can tell.

@nelsonghezzi
Copy link
Author

Hi @Xiard.

I've tested the solution proposed by @JamesNK , and it has worked on the sample project I've submitted to repro the issue.

However, it didn't work in my main solution, which is quite similar to yours (a main App project with a number of surrounding assemblies, and the mappings declared on one of them).

I've debugged with Automappers' sources referenced directly in the solution, but it didn't gave me any more clues.

Who knows, maybe this is actually an error in the .NET Native compiler.

I also don't know if Automapper can provide an .rd.xml file (as I thought initially) to solve this, because it cannot anticipate on which type(s) the generic extension methods are going to be closed, as it depends on the classes being mapped.

For me is a dead end right now. Even tried a hard workaround, turning the problematic method (BuildPublicNoArgExtensionMethods) into a no-op, but then got another (different) .NET Native error further down in the mappings.

I do not know if I'll be able to handle all these errors in the short term, so I've started to consider removing Automapper from the project.

@Xiard
Copy link

Xiard commented Oct 19, 2015

Fortunately I was able to isolate the particular problem that was coming up for me (the setters on ignored properties) and remove my dependency on that without removing AutoMapper entirely. I'm not doing anything complex with AutoMapper yet; just using it for basic DTO - DomainObject mapping at this point. I suspect the fact that I haven't gotten too deep with it yet helped me in this case.

@Xiard
Copy link

Xiard commented Oct 19, 2015

BTW, I did have a couple of cases where I could make the setters private rather than removing them entirely. That also worked to avoid the error.

@jbogard
Copy link
Member

jbogard commented Oct 23, 2015

Closing until we can get a better repro :(

@jbogard jbogard closed this as completed Oct 23, 2015
@nelsonghezzi
Copy link
Author

Now that Automapper 4.1.0 is out, I decided to give it a try, to see if by chance the error doesn't trigger.

Unfortunately, the error was still there.

But I noticed a warning in the output of the .NET Native compiler, that I didn't saw in my previous tests (and I'm not sure if it was shown earlier):

Ambiguous type name detected. There are types with name 'System.Linq.Enumerable' in both assembly 'System.Xml.XDocument' and 'System.Linq'. This directive is ignored. Consider placing this directive within an Assembly scope.
warning : Type 'System.Linq.Enumerable' could not be found.

So, that was the cause for which the runtime directives provided by @JamesNK were ignored in my project.

The solution was to wrap the directives into an element, as the warnings suggest:

<Assembly Name="System.Linq">
  <Type Name="System.Linq.Enumerable" Browse="Required PublicAndInternal">
    <MethodInstantiation Name="ToArray" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Distinct" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Reverse" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="AsEnumerable" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="ToList" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="DefaultIfEmpty" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="First" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="FirstOrDefault" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Last" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="LastOrDefault" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Single" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="SingleOrDefault" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Any" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Count" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="LongCount" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Min" Arguments="System.Char" Dynamic="Required"/>
    <MethodInstantiation Name="Max" Arguments="System.Char" Dynamic="Required"/>
  </Type>
</Assembly>

And that's it, the directives were picked and the mapping declaration didn't throw any exception.

Then I had to add the same directives for other types like Int32, Int64, Byte, and even KeyValuePair<string, object> for the same reason. And just for the record, the way you specify that last one in the .rd.xml file is escaping the angle brackets like you do in any XML file. For example:

<MethodInstantiation Name="ToArray" Arguments="System.Collections.Generic.KeyValuePair&lt;System.String,System.Object&gt;" Dynamic="Required"/>

Sooo, with the code that sets up the mappings not complaining anymore, I've started to test the rest of the code, hitting exceptions like the one reported by @pamtaro:

Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.CoreLib.dll
Additional information: Reflection_InsufficientMetadata_EdbNeeded: AutoMapper.Mappers.CollectionMapper.EnumerableMapper<System.Collections.Generic.IList<Domain.Entities.SomeEntity>,Domain.Entities.SomeEntity>. For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485

Which gets fixed with another directive:

<Type Name="AutoMapper.Mappers.CollectionMapper.EnumerableMapper&lt;System.Collections.Generic.IList&lt;Domain.Entities.SomeEntity&gt;,Domain.Entities.SomeEntity&gt;" Dynamic="Required All" />   

Right now I'm hitting other type of exception:

Exception thrown: 'System.Reflection.MissingRuntimeArtifactException' in System.Private.Reflection.Core.dll
Additional information: Object_NotInvokable, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.GetEnumerator(). For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485

And I'll try to solve it with another directive. It'll be a long path to make this to work, but at least I'm not stuck anymore.

@jbogard: can I use the Automapper capabilities to self-test the mappings (AssertConfigurationIsValid) to trigger every declared mapping? If so, maybe that would make the search for the missing directives a little easier.

@jbogard
Copy link
Member

jbogard commented Oct 23, 2015

Yeah that actually runs every mapping.

@Xiard
Copy link

Xiard commented Oct 23, 2015

Nice job, @nelsonghezzi . Well done. I had seen that warning, but I didn't try wrapping in an Assembly directive like that. I just included all of System.Linq in an Assembly directive, assuming that would be sufficient. Perhaps that doesn't work the way I think it should? Regardless, kudos.

@PureWeen
Copy link

Has anyone tried this again with version 4.2.0? I'm getting similar but different errors when trying to compile my project in release mode.... I've attached a completely vanilla project where I've written no code and just added the AutoMapper library into

http://1drv.ms/1otmdqx

Errors

1>------ Build started: Project: AutoMapperUWP42, Configuration: Release x86 ------
1>  AutoMapperUWP42 -> C:\Users\shane\OneDrive\Recreation2\AutoMapperUWP42\bin\x86\Release\AutoMapperUWP42.exe
1>  Starting .NET Native compilation
1>  Processing application code
1>C:\Users\shane\OneDrive\Recreation2\AutoMapperUWP42\Resources.System.Linq.Expressions.rd.xml(35): warning : Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found.
1>C:\Users\shane\OneDrive\Recreation2\AutoMapperUWP42\Resources.System.Linq.Expressions.rd.xml(91): warning : Method 'ParameterIsAssignable' within 'System.Linq.Expressions.Expression' could not be found.
1>  Computing application closure and generating interop code
1>  Generating serialization code
1>  Compiling interop code
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.FieldBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.MethodBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.PropertyBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.TypeBuilder' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.ModuleBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.ProxyGenerator'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.ILGenerator' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)' will always throw an exception due to the missing method 'TypeBuilder.DefineField(string, Type, FieldAttributes)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.AssemblyBuilder' was not included in compilation, but was referenced in method 'ProxyGenerator.CreateProxyModule()'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'ProxyGenerator.CreateProxyModule()' will always throw an exception due to the missing method 'AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'ProxyGenerator.CreateProxyType(Type)' will always throw an exception due to the missing method 'ModuleBuilder.DefineType(string, TypeAttributes, Type, Type[])'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'TypeExtensions.CreateType(TypeBuilder)' will always throw an exception due to the missing method 'TypeBuilder.CreateTypeInfo()'. There may have been a missing assembly.
1>  Cleaning up unreferenced code
1>  Generating native code
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Error: NUTC302F:Invalid program detected. while compiling method 'instance System.Type AutoMapper.Internal.PropertyEmitter.get_PropertyType()'.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.FieldBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.MethodBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.PropertyBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.TypeBuilder' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.ModuleBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.ProxyGenerator'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.ILGenerator' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)' will always throw an exception due to the missing method 'TypeBuilder.DefineField(string, Type, FieldAttributes)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Type 'System.Reflection.Emit.AssemblyBuilder' was not included in compilation, but was referenced in method 'ProxyGenerator.CreateProxyModule()'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Method 'ProxyGenerator.CreateProxyModule()' will always throw an exception due to the missing method 'AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Method 'ProxyGenerator.CreateProxyType(Type)' will always throw an exception due to the missing method 'ModuleBuilder.DefineType(string, TypeAttributes, Type, Type[])'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : Method 'TypeExtensions.CreateType(TypeBuilder)' will always throw an exception due to the missing method 'TypeBuilder.CreateTypeInfo()'. There may have been a missing assembly.
1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(1129,5): error : ILT0005: 'C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\Tools\nutc_driver.exe @"C:\Users\shane\OneDrive\Recreation2\AutoMapperUWP42\obj\x86\Release\ilc\intermediate\MDIL\AutoMapperUWP42.rsp"' returned exit code 1
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

I tried various permutations of things in the default.rd.xml file

But no matter what way I specify those Emit types (here's one version)

 <Type Name="System.Reflection.Emit.MethodBuilder" Browse="Public">
        <Method Name="CreateTypeInfo" Dynamic="Required"></Method>
      </Type>

It causes this exception

1>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : Internal compiler error: Unable to cast object of type 'Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceTypeNameTypeReference' to type 'Microsoft.Cci.INamespaceMember'.

And I don't know where to go with that one..... That exception makes me think something about the thing that's walking the class is doing something wrong and throwing an exception .... That or I'm just doing something silly..

I tried a few different versions of the MyGet automapper things but I always get the same set of errors... I also tried to just add some dummy properties in my project of the missing Types to see if that'd help but it didn't..

@JamesNK
Copy link

JamesNK commented Feb 22, 2016

I get this with 4.2.0:

Invalid program detected. while compiling method 'instance System.Type AutoMapper.Internal.PropertyEmitter.get_PropertyType()'.

:\

@RCTycooner
Copy link

Hi, Got this problem with 4.2.0 as well, but only when building through TFS's build. When I use VS2015, it works.
(This is during a Release, X86 build, with .NET Native compilation enabled)

I'm seeing the following warnings and errors:

` 2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.FieldBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.MethodBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.PropertyBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.PropertyEmitter'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.TypeBuilder' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.ModuleBuilder' was not included in compilation, but was referenced in type 'AutoMapper.Internal.ProxyGenerator'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.ILGenerator' was not included in compilation, but was referenced in method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'PropertyEmitter..ctor(TypeBuilder, string, Type, FieldBuilder)' will always throw an exception due to the missing method 'TypeBuilder.DefineField(string, Type, FieldAttributes)'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Type 'System.Reflection.Emit.AssemblyBuilder' was not included in compilation, but was referenced in method 'ProxyGenerator.CreateProxyModule()'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'ProxyGenerator.CreateProxyModule()' will always throw an exception due to the missing method 'AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'ProxyGenerator.CreateProxyType(Type)' will always throw an exception due to the missing method 'ModuleBuilder.DefineType(string, TypeAttributes, Type, Type[])'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]
     2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): warning : Method 'TypeExtensions.CreateType(TypeBuilder)' will always throw an exception due to the missing method 'TypeBuilder.CreateTypeInfo()'. There may have been a missing assembly. [D:\Builds\11\CTO\Maat Main New\src\Src\Main\M.0\Client\Calidos.Maat\Calidos.Maat\Calidos.Maat.Windows\Calidos.Maat.Windows.csproj]`

(sorry, format is a bit messy, first-time commenter on github ;))

@lock
Copy link

lock bot commented May 7, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants