问题
I have developed an UWP app that works globally fine, but I encounter some problems with the Store app, or with the Release build, whereas all works fine in Debug build...
The app seems very basic: ts allows users to create and sync forms through webservices. At the launch of the app, a test is done to see if a user is already logged in: if it's not the case, the app navigates to the "Login" page, otherwise it navigates to the "Home" page, which contains the forms list. Then the user can edit each form through a "Details" page.
"Debug" mode:
When I build the app in "Debug" mode, I don't encounter any exception that isn't catched and all works fine.
The Store app:
The last version of the Store app has been successfully generated and validated without any problem. But one of my last changes raises a crash of the app, when the user coming back from the "Details" page to the "Home" page.
I suspect especially this change to raise the error: I've added some code on the "Details" view to clean the resources through "OnNavigatedFrom()":
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
ViewModel = this.DataContext as DetailsViewModel;
if (!ViewModel.ToChildNavigate)
{
// Dispose resources
this.Resources.Clear();
this.Loaded -= DetailsPage_Loaded;
ViewModel = null;
}
base.OnNavigatedFrom(e);
}
To fix this, I would like to build the app in "Release" mode with ".Net Native tool chain".
"Release" mode:
In "Release" mode, I have checked well the options "Compile with .NET Native tool chain" and "Optimize code".
The application launches correctly and navigates fine the "Login" page. But after the user's connection, the app tries to navigate to the "Home" page: I get 2 exceptions, and I can't do anything else...
The first exception occurs one time, and I can "continue":
The second exceptions occurs each time even if I try to continue:
I've tried to add some MessageDialog to see where the error occurs, but the message is not displayed in the consctructors: so I can't identify the origin of the problem...
"Debug" mode with "Native tool chain"
Finally, I've tried to build the app in "Debug" mode again, but with the options "Compile with .NET Native tool chain" and "Optimize code".
But like this, it works fine, and I can't reproduce the error encountered in "Release" mode...
I don't have another ideas, and I can't anwser to these questions:
- why are there differences between the Store version and the Release mode?
- how could I done to use the app in Release mode? is it possible to "debug" it?
- I have to launch the app in Release mode to fixe the encountered bug of the Store version...
Regards,
回答1:
Release configurations by default optimize the code which loses some artifacts used for debugging. As a result, trying to debug a Release configuration can result in some issues.
It is important to note that the Release configuration is by default fully optimized code (e.g. code inlining will be applied in many places). These optimizations will have a significant impact on the debugging experience including unpredictable stepping and breakpoint behavior (due to code inlining) and the inability to inspect most variables due to memory optimizations.
So to debug a UWP app in "Release" mode, we can create a custom configuration and enable the .NET Native toolchain for that configuration. Make sure to not optimize code.
For more details please see Debugging .NET Native Windows Universal Apps.
回答2:
I had the same problem a while ago. After a long time of try and error i was able to debug in release mode with .net native tool chain with remote debugging on another pc (in my case it was a surface).
I used Visual Studio 2017 and on the remote machine the remote debugger tools for 2017.
Hope this helps.
Greetings.
来源:https://stackoverflow.com/questions/42208803/how-to-debug-an-uwp-app-in-release-mode-net-native-tool-chain