4

We have a Windows 10 UWP app that runs fine under Debug builds and crashes under Release builds. What it is about release builds that makes it crash is that .NET Native tools chain is enabled - disabling that allows the app to run. But that's not a real fix as it needs to run with .NET Native tool chain if you intend to publish to the store.

We use Microsoft.Practices.Unity for DI. Here's an example of how we register some classes:

container.RegisterType<IBoardView, BoardView>();

And then, in our app we resolve it as follows:

container.Resolve<IBoardView>();

It works fine unless I run it with .NET Native, in which case I get the following exception:

An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code

Additional information: Resolution of the dependency failed, type = "WindowsUniversal.ViewModels.Interfaces.IBoardViewModel", name = "(none)".

Exception occurred while: while resolving.

And in the output window I get:

Exception thrown: 'System.NullReferenceException' in System.Linq.Expressions.dll

Exception thrown: 'System.NullReferenceException' in Microsoft.Practices.Unity.dll

Exception thrown: 'Microsoft.Practices.Unity.ResolutionFailedException' in Microsoft.Practices.Unity.dll

An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code

Additional information: Resolution of the dependency failed, type = "WindowsUniversal.ViewModels.Interfaces.IBoardViewModel", name = "(none)".

Exception occurred while: while resolving.

Exception is: NullReferenceException - Object reference not set to an instance of an object.

At the time of the exception, the container was:

Resolving WindowsUniversal.ViewModels.Interfaces.IBoardViewModel,(none)

All this works under Debug or Release when .NET Native is disabled. Now I know .NET Native has it's limitations, reflection being one of them. I guess I'm asking how to get around this?

Any insights would be greatly appreciated, thanks.

Glaucus
  • 848
  • 8
  • 14
  • Does this work on DEBUG with .NET Native enabled. Spurious nullrefs seem like a bug in the optimizer to me. This link may also be useful for sending us enough info to help out: https://github.com/dotnet/core/blob/master/Documentation/ilcRepro.md – MattWhilden Dec 09 '15 at 00:41
  • Good idea Matt, but unfortunately that didn't fix it. I thought there might be issues with Unity and .NET Native but non of my googling has revealing anything along those lines. I have a feeling we're doing something wrong but I'm not quite sure what yet. – Glaucus Dec 09 '15 at 15:04
  • If your program works without .NET Native and crashes when you turn it on, we'd love to get that report and help you work through the issue. After that we can report back here with, hopefully, positive results! dotnetnative@microsoft.com – MattWhilden Dec 09 '15 at 19:02

0 Answers0