Crash C# Application and Generate Dumps - c#

I'm trying to generate dumps for my C# application,
I used the FailFast method to "Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and optional exception information in error reporting to Microsoft."
static void Main(string[] args)
{
string causeOfFailure = "This is a test crash.";
try
{
Environment.FailFast(causeOfFailure);
}
finally
{
Console.WriteLine("This finally block will not be executed.");
}}
I managed to get the error on event viewer, however Dumps are not generated
This is my settings for the dumps in the registry:
I kept default values, so the Dump folder should be %LOCALAPPDATA%\CrashDumps
However, no dumps are generated

I see in your event viewer screenshot that your app uses .NET Framework 2.0. It seems the crash dump only works in .NET Framework 4.0 and above. Try changing the targeted .NET Framework.
In your Solution Explorer, right-click your project and select Properties
In Properties, go to the Application option on the side menu
Locate the Target framework dropdown and select the framework version 4.0 or above.
I tested this on my machine. When targeting .NET 2.0 there is no crash dump. When targeting .NET 4.0 I get a crash dump.

Related

What is the proper way to investigate memory leaks on .net core linux kubernetes container

I have the .net core app running on linux docker container, and while taking dumps (core 2.2 or 3.0) I can't open them in the PerfView,
taking dumps according to this instruction:
https://github.com/dotnet/diagnostics/blob/master/documentation/dotnet-dump-instructions.md
PerfView shows this error in the logs:
Creating heap dump C:\temp\dumps\dump\dump-1.gcdump from process dump C:\temp\dumps\dump\dump-1.dmp.
HeapDump Error: Microsoft.Diagnostics.Runtime.ClrDiagnosticsException: Could not load crash dump 'C:\temp\dumps\dump\dump-1.dmp', HRESULT: 0x80070057
at Microsoft.Diagnostics.Runtime.DbgEngDataReader..ctor(String dumpFile)
at Microsoft.Diagnostics.Runtime.DataTarget.LoadCrashDump(String fileName)
at GCHeapDumper.InitializeClrRuntime(String processDumpFile, DataTarget& target, ClrRuntime& runtime)
at GCHeapDumper.DumpHeapFromProcessDump(String processDumpFile)
at Program.MainWorker(String[] args)
The dump file is created inside the container and therefore not directly accessible from your machine. (If you are running Windows and Docker for Windows there is even a virtual machine inbetween.)
What you need to do is to copy the dumb file from the container to your host and open it afterwards.
This can be achieved using docker cp command, for example: docker cp <container name>:<path in container>dump-1.gcdump C:\temp\dumps\dump\dump-1.gcdump
I believe you need to use Linux debugger to open Linux dumps.
Afaik PerfView supports only Windows dump.
CoreClr team provides SOS debugger extension that can be utilized from lldb debugger.
https://github.com/dotnet/coreclr/blob/master/Documentation/building/debugging-instructions.md
Dumps on .NET core are not cross-platform compatible due to cross-platform DAC (For more info, see https://github.com/dotnet/runtime/blob/master/docs/design/coreclr/botr/dac-notes.md). There have been discussions/plans on supporting this but it hasn't happened yet.
You can use dotnet-gcdump tool and it should be cross-platform compatible. Here is a doc on how to use it: https://github.com/dotnet/diagnostics/blob/master/documentation/dotnet-gcdump-instructions.md
A dump taken from dotnet-gcdump can be viewed on PerfView.

Telerik RenderReport throws an exception "XLS rendering format is not available"

I have a C# WinForms application which is generating a .xls type report using the Telerik.Reporting dll.
We are in the process of developing an enhanced version of the application in electron using Angular. We are using EdgeJs to access the reporting features during the transition from the legacy product to the new product. That is, we are running the exact same C# code in both the legacy application and the electron app.
The problem is that the Telerik.Reporting RenderReport method throws an exception, "XLS rendering format is not available", in the electron version of the app, but not in the WinForms version. Here are the relevant lines of code:
var reportSource = new InstanceReportSource { ReportDocument = rpt };
result = processor.RenderReport("XLS", reportSource, null);
rptStream = new FileStream(path + "\\" + rpttmpXlsPath, FileMode.Create);
rptStream.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
We cannot figure out why this is happening. Here is what we know:
The data being reported is identical in both cases.
The C# code being executed is the same in both cases.
The issue is reproducible on other (non-dev) machines.
On a single developer machine (Window 7/Excel 2010), the exception does
not occur and the report generates as expected. As an added bonus, this machine also contains the Telerik license for developing the reports.
On another non-dev machine with Windows 7/Excel 2010, we get the same exception.
We have tested the application on a Windows 7/Excel 2013 machine and got the exception.
We have tried updating to the latest EdgeJs to no avail.
We also render the report in PDF which works in both apps.
Telerik Reporting engine throws such an exception when it can't resolve a required dependency for the target format, but the XLS exporting routines are embedded in Telerik.Reporting.dll so it's not likely that you're missing an assembly file. XLS rendering also doesn't have any external dependencies in contrast with XLSX rendering, which requires DocumentFormat.OpenXml.dll. You'll have to collect more information about the exception to see what causes the problem. Usually helps to attach a trace listener to your application and examine its logs to see the exception stack trace or another important details. Another option is to use the Assembly Binding Log Viewer that displays information for assembly binds and see if its log will give you any hint about what's happening. Please note that the product requirements include .NET Framework 4+ Full Profile and consider if it's applicable to your scenario.

Instance of AggregateException causes TargetInvocationException

I have a problem that an instance of an AggregateException causes a TargetInvocationException after a couple of accesses to an Icon resource.
I broke down the problem to the following steps to reproduce (.Net 4.0 full or client profile):
Create a new WinForms application (a console application will not work)
Add an arbitrary icon (.ico file) to the resources
Add the following code to the constructor:
new AggregateException();
for (var i = 0; ; ++i)
{
var icon = Resources.Certificate;
}
You have to change the resource name to the name of your resource.
That's all. Yes I know that this sample doesn't make sense. It's just to illustrate the problem. My working code is much more complex and all of this code is needed.
Without creating this excection the application will work forewer. But if this exception is created the access to the resource will fail with a TargetInvocationException. The InnerException told me that the operation has been finished successfully(?!?!) having a two-line stack trace in System.Drawing.Icon (ctor + Initialize).
What can I do to prevent this problem?
EDIT
It seems to be a problem using Windows 7. A binary which fails on Win 7 will run correctly in Win 8.1.
I found the reason for that problem:
The following system configuration is needed to reproduce the issue:
Windows 7 German Edition
Microsoft .Net Framework 4.5.2 installed (yes I know my binary is compiled against .Net 4.0)
KB2901983 installed
Having a machine which only contains the .Net Framework without KB2901983 the program works fine. After installing KB2901983 the program fails for the same binary (no recompilation required).
I tried to uninstall KB2901983 but it doesn't help. If it was once installed the program will fail. I tested it on a clean Windows 7 German Edition.

TypeLoadException from log4net LogManager.GetLogger

I'm attempting to use log4net to provide logging in a Windows CE/Windows Embedded project. However, when debugging the project I get the following exception
System.TypeLoadException occurred
Message="TypeLoadException"
StackTrace:
at log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name)
at log4net.LogManager.GetLogger(Type type)
at Sis.SiLogCE.Broker.StartBroker..cctor()
at Sis.SiLogCE.Broker.EntryPoint.Program.Main()
from the following line:
private static readonly ILog log = LogManager.GetLogger(typeof(StartBroker));
At first, I thought I might have been using the wrong dll/an old dll so I downloaded the most recent version - I am using the log4net.dll from 1.2.12-bin-newkey and found in .net-cp 3.5.
I've looked though other examples and though the documentation and I can see no reason why I'm getting a type load exception here. I'm now pretty much out of ideas as to what couple be causing the exception.
Background information:
Application is to be deployed on Windows CE 6 and Windows Embedded/Windows Mobile 6 and 6/5 devices.
.net 3.5
.netcf
The following block shows loading the config for log4net from an XML file named "log4net.config".
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().
GetModules()[0].FullyQualifiedName) + "log4net.config";
if (File.Exists(path))
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
}
EDITS:
Up until now, I've only tested on Wince 6.0 so I've just had a shot with Windows Mobile 6.5 - it's no different, the same exception is presented.
Are you using the binary release, or have you built from source ? I ask as this page mentions that Compact Framework 1.0 & 2.0 are not supported by the binary release, but are supported if built from the source release.

How can I solve a TypeInitialization exception in my app when deployed?

My app runs fine on my machine (of course/famous last words). However, when deploying it to another machine on the network, it won't even start up. I ran my EventLog utility on that machine and it told me this:
Type:Error
Source: .NET Runtime
Time Generated: 06/12/2012 15:35:12
Message: Application: duckbilledPlatypus.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitialization
Exception
Stack:
at duckbilledPlatypus.PlatypusMainForm..ctor()
at duckbilledPlatypus.Program.Main()
So it's something in my main form's constructor that's the problem, apparently...which, I admit, is a little "busy":
InitializeComponent();
foreach (string arg in Environment.GetCommandLineArgs())
{
if (arg == "-DEBUG")
{
InDebugMode = true;
break;
}
}
SuspendLayout();
tsch = new ToolStripControlHost(dateTimePickerScheduleDate);
toolStripPlatypusMain.Items.Add(tsch);
CreateTableLayoutPanelAndChildren();
LimitPlatypusIDTextBoxesToOneChar();
ShareEventsAmongDynamicTextBoxes();
SetAllPlatypusDataControlsReadOnly();
ResumeLayout();
Does any of this look problematic? (it's all pretty standard stuff, except for the ToolStripControlHost).
Now as to the framework version: does the Event Log report the framework version used to create my app, or the framework version installed on the machine trying to run the app? If the former, and the latter does not have that framework installed, that's a problem, right?
So if that's potentially the problem, how do I determine which version of the .NET runtime is installed on that machine?
UPDATE
I don't know why this is, but I was able to see an err msg after running the app on the remote/deployment only when I right-click and select Run As (and ran as myself, as I don't have any "more special" privileges on that machine). When I did so, I got "Unable to find a version of the runtime to run this application."
If I simply 2-click the app, it dies without a whimper (no err msg).
View the
view the %WINDIR%\Microsoft.NET\Framework directory
to determine which versions of .NET are installed.
http://msdn.microsoft.com/en-us/library/y549e41e.aspx
Try running the Fusion Log Viewer on the problematic machine. It will provide details about binding failures.
http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx
Make sure you run it as administrator. It silently fails if you do not.
UPDATE
Based on your error "Unable to find a version of the runtime to run this application.", I would suggest you don't have the same version of .NET installed on the box that your application targets. Did you verify the installed versions using the steps above?
Also see
.Net framework - "unable to find a version of the runtime to run this application"

Categories