Why does Raygun on .NET Native cause my app to crash?

1

I'm working on a Windows 10 Store application where I'm using Raygun.io (5.2.0). We released the app couple of times (latest in mid December) I see in Rayguns web interface the logs coming from previous versions. While testing the app now before publishing next version I found out that Raygun is not working anymore (= crashing) when sending exceptions if app is build using .NET native toolchain. I can reproduce this in a simple UWP test app:

public sealed partial class MainPage : Page
{
    //private readonly RaygunClient _raygunClient;

    public MainPage()
    {
        InitializeComponent();

        RaygunClient.Attach("<app_key>");
        //_raygunClient = new RaygunClient("<app_key>");
    }

    private async void OnClick(object sender, RoutedEventArgs e)
    {
        try
        {
            // this is crashing the app when project is build using .NET native toolchain
            // it is not even throwing exception
            //await _raygunClient.SendAsync(new InvalidOperationException("Raygun Test"));
            await RaygunClient.Current.SendAsync(new InvalidOperationException("Raygun Test")); // (1)
            Status.Text = "Ok";
        }
        catch (Exception exception) // (2)
        {
            Status.Text = $"Failed with {exception.Message}";
        }
    }
}

Checking https://github.com/MindscapeHQ/raygun4net supported platforms/frameworks, it doesn't seem to support explicitly UWP.

UPDATE: The application is killed after line (1), there is no exception caugh at (2) In Event View I can see:

Faulting application name: rayguntest.exe, version: 1.0.0.0, time stamp: 0x56a0edc9
Faulting module name: mrt100_app.dll, version: 1.0.23406.0, time stamp: 0x561408ce
Exception code: 0x80000003
Fault offset: 0x000000000000a0ad
Faulting process id: 0x305c
Faulting application start time: 0x01d1545a0fea5649
Faulting application path: C:\Projects\rayguntest\rayguntest\bin\x64\Release\AppX\rayguntest.exe
Faulting module path: C:\Program Files\WindowsApps\Microsoft.NET.Native.Runtime.1.1_1.1.23406.0_x64__8wekyb3d8bbwe\mrt100_app.dll
Report Id: 52bbeeb5-97c6-4814-b5dc-51ee6c3fa9bd
Faulting package full name: 6ca59c51-ed22-482b-acf6-12d241079f4d_1.0.0.0_x64__1d8r4kqm7qz2y
Faulting package-relative application ID: App
c#
uwp
raygun
asked on Stack Overflow Jan 21, 2016 by cosmo • edited Jan 21, 2016 by cosmo

2 Answers

3

We have completed our investigation and this is indeed a bug inside of .NET Native. The issue is that for some cases we didn’t properly handle all cases involving invalid casts. Specifically casting Arrays to a generic type with more than one generic parameter. You can see the spots in Raygun where we are going to run into issues by examining SimpleJson.SerializeValue: https://github.com/MindscapeHQ/raygun4net/blob/67c4bb9fd660afb91d62e9333d75a36a85ee5d4f/Mindscape.Raygun4Net/SimpleJson.cs#L1016

One workaround would be to avoid having this code path serialize an Array in the first place. Another, would be to patch RayGun to check for the array case first and avoid all of the other guesswork it’s trying to do.

The reason you don't see an exception is because the runtime is pretty defensive about the various asserts and fall troughs so it calls the OS FailFast in these cases.

Hope that helps.

answered on Stack Overflow Jan 26, 2016 by MattWhilden • edited Jul 24, 2018 by MattWhilden
0

Excerpt from Microsoft:

If the necessary metadata or implementation code is absent at runtime, the .NET Native runtime throws an exception. You can prevent these exceptions, and ensure that the .NET Native tool chain includes the required metadata and implementation code, by using a runtime directives file, an XML file that designates the program elements whose metadata or implementation code must be available at runtime and assigns a runtime policy to them.

From Microsoft on .NET Native and Compilation:

The resulting app that is produced by the .NET Native tool chain is written to a directory named ilc.out in the Debug or Release directory of your project directory. It consists of the following files:

appName.exe, a stub executable that simply transfers control to a special Main export in appName.dll.

appName.dll, a Windows dynamic link library that contains all your application code, as well as code from the .NET Framework Class Library and any third-party libraries that you have a dependency on. It also contains support code, such as the code necessary to interoperate with Windows and to serialize objects in your app.

•mrt100_app.dll, a refactored runtime that provides runtime services such as garbage collection.

answered on Stack Overflow Jan 21, 2016 by Black Frog

User contributions licensed under CC BY-SA 3.0