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

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

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.

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.

Related

APPCRASH StackOverflowException clr.dll c00000fd

I am running a .Net console application that executes 24 hrs a day. It has a bug that occurs about once every 6 days.
I would like your assistance to fix this bug. First I will provide some background, and then I will provide the exception messaging.
Unfortunately I do not have steps to reproduce. You will see why as you read on.
First some background:
I have robust exception handling in my code (or so I thought). For example I have a try...catch block in my Main() method that captures any unhandled exceptions and if they are FATAL it restarts the underlying task. It works great for any exceptions generated from my own code.
I cannot explain why the below exception isn't handled in my code. My best guess is that clr.dll exceptions do not get caught within the managed stack. And if that is the case, I do not know how to generate a stack trace. I don't even know where to begin to fix this.
The process I am running is using the following versions and modules:
C# .Net Framework 4.6.1
Console App project type
System.Net.WebClient
log4net
Windows 7 64-bit
At the time of the crash I checked RAM and HDD: both have plenty of free space.
About the code I'm executing. The process is a continous loop that downloads data from a website and saves it to a text file. If there is an error, it is logged using log4net.
The basic loop is this:
for (int i = 0; i < 5; i++)
{
try
{
return new WebClient().DownloadString(url);
}
catch
{
Thread.Sleep(500); // slow it down.
}
}
The following is the only message that displays in my console window when the exception occurs: (no stack trace displayed)
Process is terminated due to StackOverflowException
My console application completely freezes up and a dialog window pops up with the following information (closing this dialog also terminates my application)
Problem signature:
Problem Event Name: APPCRASH
Application Name: foo.goo.BatchExecutor.exe
Application Version: 1.0.0.0
Application Timestamp: 5a50f3eb
Fault Module Name: clr.dll
Fault Module Version: 4.7.2117.0
Fault Module Timestamp: 59cf5105
Exception Code: c00000fd
Exception Offset: 0002429f
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 28e8
Additional Information 2: 28e8aacd8abfe32876bc8363e8e5c526
Additional Information 3: 6916
Additional Information 4: 6916665ca52ff482d854f190abcf46b2
The only other place I could find information about the crash is in the Windows Event Log:
Log Name: Application
Source: Application Error
Date: 1/23/2018 5:51:46 PM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: FOOGOO
Description:
Faulting application name: foo.goo.BatchExecutor.exe, version: 1.0.0.0, time stamp: 0x5a50f3eb
Faulting module name: clr.dll, version: 4.7.2117.0, time stamp: 0x59cf5105
Exception code: 0xc00000fd
Fault offset: 0x0002429f
Faulting process id: 0x1e00
Faulting application start time: 0x01d39169354e41a7
Faulting application path: C:\Users\Owner\Desktop\SHARED\foo.goo.BatchExecutor\foo.goo.BatchExecutor.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: 21b9b2a4-00a9-11e8-9f6c-94c69110a719
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Level>2</Level>
<Task>100</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2018-01-24T01:51:46.000000000Z" />
<EventRecordID>1852</EventRecordID>
<Channel>Application</Channel>
<Computer>FOOGOO</Computer>
<Security />
</System>
<EventData>
<Data>foo.goo.BatchExecutor.exe</Data>
<Data>1.0.0.0</Data>
<Data>5a50f3eb</Data>
<Data>clr.dll</Data>
<Data>4.7.2117.0</Data>
<Data>59cf5105</Data>
<Data>c00000fd</Data>
<Data>0002429f</Data>
<Data>1e00</Data>
<Data>01d39169354e41a7</Data>
<Data>C:\Users\Owner\Desktop\SHARED\foo.goo.BatchExecutor\foo.goo.BatchExecutor.exe</Data>
<Data>C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll</Data>
<Data>21b9b2a4-00a9-11e8-9f6c-94c69110a719</Data>
</EventData>
</Event>
*****UPDATE WITH SOLUTION WORKAROUND *****
I have given up trying to handle this exception within .Net. I found an effective workaround. This workaround applies to Windows, specifically any version with an Event Viewer.
Workaround Instructions.
1) Open control panel->Admin Tools->Event Viewer->Windows Logs->Applications.
2) Select the offending event. In my case, it is state ERROR, and matches the example that you see above.
3) On the right hand side click "Attach Task to This Event".
4) Complete the wizard. In my case, I restart my application.
5) Save the task.
6) Now switch over to Task Scheduler and find the task. Click Properties. Click through the tabs and configure the Task as you see fit.
*****UPDATE WITH SOLUTION WORKAROUND *****
I have given up trying to handle this exception within .Net. I found an effective workaround. This workaround applies to Windows, specifically any version with an Event Viewer.
Workaround Instructions.
1) Open control panel->Admin Tools->Event Viewer->Windows Logs->Applications.
2) Select the offending event. In my case, it is state ERROR, and matches the example that you see above.
3) On the right hand side click "Attach Task to This Event".
4) Complete the wizard. In my case, I restart my application.
5) Save the task.
6) Now switch over to Task Scheduler and find the task. Click Properties. Click through the tabs and configure the Task as you see fit.
I suggests to use ProcDump, it can be configured to generate a crash dump when the StackOverflowException occurs.
procdump -accepteula -e 1 -f C00000FD.STACK_OVERFLOW -g -ma <PID> <OUTPUT PATH>
Then analyze the dump file using one of this tools
Visual studio, windbg, debugdiag, clrmd.
I suggest trying DebugDiag (https://www.microsoft.com/en-us/download/details.aspx?id=49924) to capture the crash and analyse the resulting process dump. Make sure you include pdbs alongside your exe, to make diagnosis easier: in the Project properties, Build tab: set the Configuration to the configuration that you use to build the exe. In the Output section, Advanced button, set the Debugging information to Pdb (or Full).
To help collect a stack trace, PHPTower, you can do what I did and subscribe to the AppDomain.CurrentDomain.UnhandledException event of your program at the beginning of your Main() function
The signature of the event handler looks like the following, allowing you to get the exception, and output a stack trace with the Exception.ToString() method.
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
File.AppendAllLines(FileName, e.ExceptionObject.ToString());
}
Happy hunting!
-cadatoiva

XamlParseException and NoServiceException

My programm is running without any problems, on my current laptop (x64). But when I try to run it on an other PC (x86) it crashes before starting. I also tried to change the platformtarget, as described in this answer:
XMLParseException occurs
I also catched all unhandled exceptions. That delivers me two exceptions:
I also got that from reliability history:
Faulting application name: LoginDemo.exe, version: 1.0.0.0, time
stamp: 0x56c19003 Faulting module name: KERNELBASE.dll, version:
6.1.7601.17651, time stamp: 0x4e2111c0 Exception code: 0xe0434352 Fault offset: 0x0000d36f Faulting process id: 0x4b0 Faulting
application start time: 0x01d167cd96535e01 Faulting application path:
C:\Users\hgservice\Desktop\Temp\LoginTool2\LoginDemo\bin\Release\LoginDemo.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll Report Id:
d6435b26-d3c0-11e5-b9a7-001999d6cbe5
I also read that the problem could occure because the programm tries to import a DLL while running, but all DLLs that I need for the exe are in the same folder. And as I said on my laptop it is working fine. Has anyone an idea what the problem could be?
This problem has nothing in common with WPF as such. If we analyse the stacktrace we can see that it is thrown by pcsc-sharp library. The more careful analysis will show that NoServiceException exception was thrown because the following native method returned an error:
[DllImport(WINSCARD_DLL, CharSet = CharSet.Auto)]
private static extern int SCardEstablishContext(...)
More precisely NoServiceException is mapped to the SCARD_E_NO_SERVICE (0x8010001D) error. It means that probably SmartCard service on your laptop is not running. To fix it: press Win+R, type services.msc and start SmartCard service.
This problem can be also caused by differences between various versions of Windows (for details see this question).
Another cause of this problem might be the lack of sufficient permissions (see this article).
Okay guys I fixed it. As Michał Komorowski and Jon Skeet already answered, the problem was that the Smard Card sevice was not running. The answer of Michał Komorowski is almost correct. The only thing I had to do furthermore, was to set the startup type on "manual". After that I could start the Smart Card service and now everything is working.

Buffer Overflow in clr.dll at application start-up

I have two computers. Both work under Windows 7 Embedded and have same version of .Net 4.0 framework installed.
My WinForms application works with no issues on one of them but fails at start-up with BEX in clr.dll on another.
Problem Event Name: BEX
Application Name: Myapplication.exe
Application Timestamp: 5669ec33
Fault Module Name: clr.dll
Fault Module Version: 4.0.30319.526
Fault Module Timestamp: 4eb3b6b1
Exception Offset: 002b65ec
Exception Code: c0000409
Exception Data: 00000000
OS Version: 6.1.7601.2.1.0.320.65
Locale ID: 1033
Additional Information 1: a835
Additional Information 2: a835052745ddb3bce091e0cd181de7e7
Additional Information 3: 7cb8
Additional Information 4: 7cb8eec426d05584b36071af9d74719d
What is very "strange"
I was able to find two things in my application that somehow have impact or provoke this problem.
First I found exact line of code.. I have few buttons that I manually create manually on UI thread. And if I remove next line my application starts.
btn.Font = new Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point, 0);
Second I noticed that if I use my debug logger which uses StackFrame to find out where log message is coming form, Application will crash with the same error in CLR but at some other place. Not at the line I mentioned above.
My two computers have different RAM. 2GB and 1GB. Application fails on the second one with 1GB of memory. But application iself uses 30 MB and system has ~350 MB of free memory. Could memory be a reason ?
My research for the most part referred me to different hot-fixes issued by Microsoft. I tried them but nothing helped. I also tried to install .Net v4.5 but with the same negative result.
Where else I can start looking for the problem ?
... And yes, this problem does not show up when running application with attached debugger.
Update
I just realised that "Exception Code: c0000409" means STATUS_STACK_BUFFER_OVERRUN. This brings some sense to strange application behaviour that I have but still not clear why it works on one computer but does not work on another.
Solution finally found
My application uses third party C# library which is actually a wrapper on top of calls to other native library. I decompiled library and realised that calling convention is set to CallingConvention.Cdecl but as I see from Dependency Walker application, all methods in native library has CallingConvention.StdCall
After changing calling convention and recompiling the library issue disappeared.

System.IO.FileLoadException from WshShell.Exec in Classic ASP on IIS 7.5

I’m using the DidiSoft OpenPGP for .NET library to compile C# into an exe that gets executed by Classic ASP. The goal is to update the security on this legacy website to use PGP. It’s an old site so we can’t rewrite it without significant cost.
The reason I tried to use this library was that when we would call compiled C# EXE’s that referenced:
using System.Security.Cryptography;
I would get a blank output in ASP, and IIS would throw an error in Event Log similar to this:
Faulting application name: PGPTest.exe, version: 1.0.0.51, time stamp: 0x52f28ee5
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18229, time stamp: 0x51fb1116
Exception code: 0xe0434352
Fault offset: 0x0000c41f
Faulting process id: 0x5f08
Faulting application start time: 0x01cf22a83ae734f4
Faulting application path: d:\inetpub\_bin\[redacted website name]\PGPTest.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: 789751fa-8e9b-11e3-87e1-0050568e508f
Application: PGPTest.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException
Stack:
at PGPTest.Program.Main(System.String[])
================
.NET Runtime version 4.0.30319.1008 - There was a failure initializing profiling API attach infrastructure. This process will not allow a profiler to attach. HRESULT: 0x80004005
Process ID (decimal): 24328. Message ID: [0x2509].
So when I use either the DidiSoft OpenPGP or System.Security.Cryptography I get errors.
In Classic ASP the application is called with:
WshShell.Exec(%pathtoexe%)
We do receive output IF if we change the Application Pool to run under LocalSystem instead of NetworkService. So it seems to be related to permissions somehow.
Our server is running:
Server 2008 R2
.NET 4.0
We're assuming running the application pool under LocalSystem is unsafe; is this correct?
Any ideas on how we can get this to work?
Thank you
Update: The author of the library has confirmed to me that it does use System.Security.Cryptography for some of its algorithms.
Update 2: To ulluoink: If you read this at all you'd realize that this DOES in-fact have to do with Classic ASP. How do I know you ask? Because when moving the code from a C# app that Classic ASP executes into a ASP.NET 4 Web API app, the SAME EXACT CODE on the exact same server works just fine. It appears to be a permissions issue tied DIRECTLY to Classic ASP's execution privileges.
So, the current work around is to deploy our code that references System.Security.Cryptography to the same server in an ASP.NET Web API app. We're POSTing to the ASP.NET app in Classic ASP; specifically sending data serialized with this: http://www.aspjson.com/
Yes running a site exposed to the internet as LocalSystem is unsafe. You can use filemon or processmon while loading the page to see which files need permissions from which users.
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

.NET application won't open in windows 7

I created a pretty simple c# application using visual studio 2010 on windows xp. It compiles, runs and debugs fine on my machine. I even built it for release and ran the .exe on my machine and another windows xp machine perfectly fine. When I send the release folder with the .exe file and they open it, nothing happens! No errors or anything, just blank!
.NET version 4 framework installed
It is a windows form application.
UPDATE: Details from OP's comments given to one of the answers below:
Hey everyone, thanks for the ideas. I
copied what I found on my friends
windows 7 machine event log and this
is what it said:
Application: ePrescribing.exe Framework Version: v4.0.30319
Description: The process was
terminated due to an unhandled
exception. Exception Info:
System.IO.FileNotFoundException Stack:
at
ePrescribing.frmApp.InitializeComponent()
at ePrescribing.frmApp..ctor() at
ePrescribing.Program.Main()
Faulting application name: ePrescribing.exe, version: 1.0.0.0,
time stamp: 0x4d61e693 Faulting module
name: KERNELBASE.dll, version:
6.1.7600.16385, time stamp: 0x4a5bdbdf Exception code: 0xe0434352 Fault
offset: 0x0000b727 Faulting process
id: 0xb38 Faulting application start
time: 0x01cbe1dbe6d4ba2d Faulting
application path:
C:\Users\Duane\Downloads\ePrescribing.exe
Faulting module path:
C:\Windows\syswow64\KERNELBASE.dll
Report Id:
266adc61-4dcf-11e0-8438-e0cb4e197cde –
Fault bucket , type 0 Event Name: CLR20r3 Response: Not available
Cab Id: 0 Problem signature: P1:
eprescribing.exe P2: 1.0.0.0 P3:
4d61e693 P4: ePrescribing P5: 1.0.0.0
P6: 4d61e693 P7: 28 P8: e P9:
System.IO.FileNotFoundException P10: –
I removed the only area where I
thought there would be a file load
(for the picturebox loading
profile.jpg) and still got the same
error. Any ideas?
First, you might try checking the Event Viewer for any relevant errors messages (as stated above).
Next, make sure they have .NET installed (as stated above).
Then, try adding an UnhandledExceptionEventHandler to your application and in that handler, try to at least write a simple log/text file containing the exception that caused your application to exit.
Make sure the latest .NET framework is installed.
Check .NET framework installed on win7 computer equal your application framework target.
Check in the process explorer that it's running but didn't show you anything.
Check event log for crash reports.
Try to add logging to your application in different places and add unhandled error handlers.
Additionly to other answers I would also check whether your app compiled against x86/x64 runtime
Have you included a manifest file?
Take a look at this.
Or this...
Are you accessing any folders via static paths instead of environment variables? That could cause issues between these versions of Windows.
You should check if all other third party assemblies can be found either in GAC or app folder
Referenced assembly may be missing from target computer. Please set Copy Local=True for all referenced library. This may solve your issue.

Categories

Resources