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
cosmo
  • 187
  • 2
  • 11
  • What does "crashing" mean? What is the exception? – mason Jan 21 '16 at 14:09
  • It means that the application is killed and there is no exception. – cosmo Jan 21 '16 at 14:49
  • Nah, there's always an exception. It may not be caught by C# but there's an exception somewhere. Have you tried checking the Windows event logs? – mason Jan 21 '16 at 14:50
  • I updated question with Event Viewer log description. Nothing relevant found googling. – cosmo Jan 21 '16 at 15:05
  • It is the exception that's raised by Debugger.Break(). It is trying to tell you something but since no debugger is attached, the app crashes. If you cannot repro this on your own machine then contact the vendor for support. – Hans Passant Jan 21 '16 at 16:15
  • Using the code above, Mindscape.RayGun4DotNet v 5.2.0, Visual Studio Update 1, I am not able to reproduce the crash. Perhaps you're on an older build of VS and UWP tools? – MattWhilden Jan 23 '16 at 00:35
  • @MattWhilden I'm using Visual Studio Enterprise 2015 Update 1 and Visual Studio Tools for Universal Windows Apps 14.0.24720.00 – cosmo Jan 23 '16 at 10:45
  • I work on the .NET Runtime an Compiler team. Unfortunately, it's not obvious what could be happening here. I'd be happy to take a look if you follow the instructions here: https://github.com/dotnet/core/blob/master/Documentation/ilcRepro.md – MattWhilden Jan 23 '16 at 20:29
  • I spoke too soon. I completely botched my copy/paste and now I hit the error. I'll send some more info in a bit after I figure out what's going on. – MattWhilden Jan 23 '16 at 20:34
  • Okay this appears to be a bug in .NET Native. The reason you don't see an exception is because it's a failure inside the type system and that causes us to call the OS FailFast. If you send a mail to dotnetnative@microsoft.com we'll try to get a workaround for you. – MattWhilden Jan 23 '16 at 21:25
  • Thanks @MattWhilden. I just did that. – cosmo Jan 24 '16 at 08:53
  • Wonderful. We'll get it worked out over email and can post back here once we've sorted it out. :-) – MattWhilden Jan 24 '16 at 21:33

2 Answers2

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.

MattWhilden
  • 1,686
  • 13
  • 18
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.

Black Frog
  • 11,595
  • 1
  • 35
  • 66
  • So what you are suggesting is that Raygun is using Reflection? I tried to add runtime directive () enabling everything for Mindscape.Raygun4Net, same behaviour. – cosmo Jan 21 '16 at 16:08