Automapper: Automapper fails when using .NET Native - Part 2

Created on 22 Feb 2016  Â·  28Comments  Â·  Source: AutoMapper/AutoMapper

See https://github.com/AutoMapper/AutoMapper/issues/901#issuecomment-186448990

AutoMapper 4.2.0 will no longer even compile with .NET Native.

Bug

All 28 comments

@jbogard I guess we should use dynamic compilation only on the full framework.

You guys appear to be having a lot of trouble with .NET Native. Have you emailed the team at Microsoft? They'll help you.

Actually nobody cares :)

So you have emailed [email protected] and got no reply?

@JamesNK is this something I can do as part of the build? I'd rather see failures at compile time

I don't know. Email the experts. They'll help you.

[email protected]

This prevents AutoMapper from being referenced in any app that will be uploaded to the Windows App Store. Attempting to build a Universal Windows App with AutoMapper referenced results in a host of errors such as:

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

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.

From what I can tell, the errors are related to reflection, which I know has to be handled with care when compiling via .NET Native as described here: https://msdn.microsoft.com/en-us/library/dn600640%28v=vs.110%29.aspx

I sent a note to the .NET Native folks. I assume that I'll have to strip out any Reflection.Emit stuff, not a big deal there are fallbacks for those.

Just curious, did you get any reply from the .net native team?

@jbogard Hi Jimmy! I contacted with one person from MSFT and asked him to investigate or force internally your request. I have the same issue as @babelshift mentioned at previous post (Error: NUTC302F:Invalid program detected. while compiling method 'instance System.Type AutoMapper.Internal.PropertyEmitter.get_PropertyType()'). While there is an investigation of this issue on MS side - could you let me know the status of your request? Did .NET Native team answered something? What are your next plans regarding to AutoMapper package for UWP 10?

Shame that there's not a lot of activity on this issue :(

We're building a new Universal Windows App and are unable to use AutoMapper due to this issue. We would be really glad to see a fix!

@nabels-coolblue I'm more than happy to accept a pull request. What I asked of the MS team was how to see this error at compile time. I can fix it once, but how can I fix it going forward? No response yet.

@jbogard I hit this error at compile time when compiling a Universal Windows App in Release mode (compiles using .NET Native) by default. There's probably a way to invoke the .NET Native compiler from command line, but I don't know how.

Notice in this screenshot the checkbox for .NET Native compilation.

capture

  1. Create UWP project.
  2. install-package AutoMapper.
  3. Change build type to Release (or just check the .NET Native box).
  4. Compile.

@babelshift how about with a class library?

@jbogard I join to @babelshift comment - when I pressed reply and e-mail and was going to insert the same picture I discovered that he was ahead of me :) I just have one comment - looks like you won't see this error message because libraries don't process with .NET Toolchain by themself - only being joined to some application. So you need to create UWP application, then to install package and try to build it in Release mode with .NET Toolchain enabled as shown above.

@jbogard I'm not sure. All the documentation that I've read said it only works with UWP projects right now and that Microsoft is "looking to unify across experiences." That seems like market-speak for "soon."

A fairly good StackOverflow answer: http://stackoverflow.com/questions/31981569/how-to-configure-net-native-in-visual-studio-2015

I can't get UWP apps to even install the 5.0 stuff, now that I've moved to the .NET platform standard.

Sigh.

Just to signal interest: +1 developer here who's hitting this exact issue (UWP app using Automapper fails to build in release mode).
Thanks for this great lib!

So not the greatest solution but if you're not using the Proxy generation features of AutoMapper you can remove that code, recompile and that works ... i have a fork here off of 4.2.1 where I did that

https://github.com/PureWeen/AutoMapper/tree/master

or just snag the dlls from
https://github.com/PureWeen/AutoMapper/tree/master/dotnet5.1

For my simple use of AutoMapper it's been working fine so far...

The netstandard1.1 target doesn't have proxy generation, so what SHOULD happen with the latest version is it picks up _that_ target.

But I can't tell because the MS packages for UWP haven't been updated yet for RC2 https://www.nuget.org/packages/Microsoft.NETCore.UniversalWindowsPlatform

Thanks PureWeen, your workaround worked :)

Looks like this is working in the 5.0.1 branch. Can someone else here confirm from the MyGet feed?

As far as automapper and release mode goes...

I added 1.3 manually into all my libraries and it compiled in release mode so it seems like it works... Just not sure if my package manager woes are specific to me or not

What state is the .netstandard stuff in relation to the nuget package manager install process? I know when it was dotnet5.1 VS had some issues updating PCL libraries...

I ask because I can't quite get Automapper 5.0 through nuget or the myget one to install through the nuget package manager.
If I download the package, unzip, and then just manually add .netstandard 1.3 to all my projects it seems to work great. But when I tried to install through VS package manager... I'd get this

One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).

When I try through Xamarin Studio to update my PCL libraries just to version 5.0 that's in nuget I get this

'AutoMapper' already has a dependency defined for 'Microsoft.CSharp'.

I should have the latest bits ... I have Update 3 installed and I have the latest 5.0 version of the nuget manager..

5.0 does not work. 5.0.1 _should_ work, from the myget because I removed
that IL generation stuff from netstandard..

Should.

On Fri, Jul 1, 2016 at 3:01 PM, Shane Neuville [email protected]
wrote:

As far as automapper and release mode goes...

I added 1.3 manually into all my libraries and it compiled in release mode
so it seems like it works... Just not sure if my package manager woes are
specific to me or not

What state is the .netstandard stuff in relation to the nuget package
manager install process? I know when it was dotnet5.1 VS had some issues
updating PCL libraries...

I ask because I can't quite get Automapper 5.0 through nuget or the myget
one to install through the nuget package manager.
If I download the package, unzip, and then just manually add .netstandard
1.3 to all my projects it seems to work great. But when I tried to install
through VS package manager... I'd get this

One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).

When I try through Xamarin Studio to update my PCL libraries just to
version 5.0 that's in nuget I get this

'AutoMapper' already has a dependency defined for 'Microsoft.CSharp'.

I should have the latest bits ... I have Update 3 installed and I have the
latest 5.0 version of the nuget manager..

Nothing worked at all when I first tried :-( but then I wiped out my
user/nuget package dir and then it started working..

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AutoMapper/AutoMapper/issues/1131#issuecomment-230035546,
or mute the thread
https://github.com/notifications/unsubscribe/AAGYMmEbQGLDESxm7o8zCcXQBsnBhdDsks5qRXH9gaJpZM4HfScb
.

Yay

Sounds good I just figured I'd mention it because even if I set myget as my source and try to install 5.0.1-alpha through VS I get those exceptions and it fails to install.. But just manually adding the DLL to the projecs works. Good to hear it'll all work in 5.0.1.. :-) Now I'll get the performance goodies of 5.0 and not have to update my fork..

If I "ignore dependencies" it looks like I can install version 5.0 into the PCL libraries from VS and it doesn't try to do all that stuff with the System.* libraries..... Xamarin just doesn't work at all for updating those package but that probably falls under the not AutoMappers problem category :-) And they just haven't updated their stuff to work with the netstandard 1.1/1.3 bits

Well the NuGet thing is a little distressing, that's supposed to be fixed
in the 5.0.1 alphas. It worked for me locally, but I cleared out my nuget
cache for AutoMapper.

On Fri, Jul 1, 2016 at 3:56 PM, Shane Neuville [email protected]
wrote:

Yay

Sounds good I just figured I'd mention it because even if I set myget as
my source and try to install 5.0.1-alpha through VS I get those exceptions
and it fails to install.. But just manually adding the DLL to the projecs
works. Good to hear it'll all work in 5.0.1.. :-) Now I'll get the
performance goodies of 5.0 and not have to update my fork..

If I "ignore dependencies" it looks like I can install version 5.0 into
the PCL libraries from VS and it doesn't try to do all that stuff with the
System.* libraries..... Xamarin just doesn't work at all for updating those
package but that probably falls under the not AutoMappers problem category
:-) And they just haven't updated their stuff to work with the netstandard
1.1/1.3 bits

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AutoMapper/AutoMapper/issues/1131#issuecomment-230045532,
or mute the thread
https://github.com/notifications/unsubscribe/AAGYMrUZbrh6E_aN4aV2E69L1klKTkxxks5qRX78gaJpZM4HfScb
.

Alright I figured it out... I have to set it to this in project.json

    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.0",

It seems that MS unlisted this version from nuget recently...
https://social.msdn.microsoft.com/Forums/en-US/3b3b6a49-0d6d-450c-8205-93a6284d6222/updated-application-to-use-microsoftnetcoreuniversalwindowsplatform-520-its-now-unlisted?forum=wpdevelop

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.

Was this page helpful?
0 / 5 - 0 ratings