I've released an app using Xamarin and Xamarin Insights. Insights now successfully informs me when the app crashed but I only get a very vague stack trace without line numbers which makes it often impossible to track down the error.
Is there any way I can set up release builds so that crashes will contain stack traces including line numbers?
Thank you,
David
Ref: Why don't I have line numbers in my stack trace?
Why don't I have line numbers in my stack trace?
In .NET you need to have the correct debug information (PDB files) alongside your dlls. Currently on iOS, it's not possible to package them, but we're working on a solution to upload them similar to how dSYMs are sent to us. On other platforms, you can bundle the .pdb files to get line numbers. There are also some known issues with getting line numbers when using async. We'll update the FAQ as we make progress on this.
Although not as useful as a proper stack trace with line numbers, you can use the following snippet to collect some line number and file name information yourself by making a simple wrapper for Insights.Report. This uses built-in .NET Callerattributes to tell you where Report was called.
public static void Report (Exception exp,
ReportSeverity severity= ReportSeverity.Error, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{ Insights.Report (exp, new Dictionary<string,object> { {"Method",memberName},
{"File Name",sourceFilePath},
{"Line Number",sourceLineNumber},
}, severity);
}
Related
Blank project repo with problematic code
I have the following code for querying all the supported Audio codec following this article using CodecQuery.FindAllAsync
try
{
var query = new CodecQuery();
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, "");
var subTypes = queryResult
.SelectMany(q => q.Subtypes)
.ToHashSet();
// Other codes
}
catch (Exception ex)
{
Debug.WriteLine(ex);
throw;
}
As the documentation mentioned,
To specify that all codecs of the specified kind and category should be returned, regardless of what media subtypes are supported, specify an empty string ("") or null for this parameter.
For empty string "", it works for CodecKind.Video but not for Audio (for both CodecCategory of Encoder or Decoder). If I specify a subtype, then it does not crash, for example:
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, CodecSubtypes.AudioFormatMP3);
What is strange about that is that even though I have a try/catch with generic Exception, the app just crashes through that one and show this instead:
I have tried restarting Windows, uninstall the UWP app and make a clean build. What is happening? How do I query all available audio codecs?
Update: after changing Debug setting, I could trace the error message:
Unhandled exception at 0x00007FFDCE5FD759 (KernelBase.dll) in ******.exe: 0xC0000002: The requested operation is not implemented.
After my testing, the content of this document is correct. When I set “” for the third parameter to find all audio codecs, the code works well. So there is not an error in this document.
You could choose the Debug options, and change Debugger type from Managed Only to Mixed. It won't fix your exception, but you can trace it with the debugger. You could refer to this reply to get more information.
I created a blank Universal Windows App project in Visual Studio 2015.
I add something like:
try {
string foo = null;
int len = foo.Length;
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex);
}
I get a stack trace like:
Exception thrown: 'System.NullReferenceException' in TestStackTraces.exe
System.NullReferenceException: Object reference not set to an instance of an object.
at TestStackTraces.App.OnLaunched(LaunchActivatedEventArgs e)
i.e., No line numbers.
How do I get line numbers to show up?
This appears to be no longer supported. I am re-posting my answer here, because when I did a search for my answer on another question, it was very difficult to find it in the search results. Hopefully this question will help people find this info easier.
Reference: windows 10 exceptions not including line numbers
Other info:
See corefx #1420 and related corefx #1797.
Also, there is this reference on SO: How to get StackTrace without Exception in Windows Universal 10 App
I have been at this for quite a while. I am using C# for Serious Game Programing, and am working on the SoundManager code found in Chapter 9 of the book, if you want an exact reference. The Code is setting up a sound manager using OpenAl, and I am having a problem with the Alut interface (if that is the right word for what it is). Here is the code that I am working on:
public void LoadSound(string soundId, string path)
{
int buffer = -1;
Al.alGenBuffers(1, out buffer);
int errorCode = Al.alGetError();
System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
int format;
float frequency;
int size;
System.Diagnostics.Debug.Assert(File.Exists(path));
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
//System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
//System.Diagnostics.Debug.Assert(data != IntPtr.Zero));
//System.Diagnostics.Debug.Write(errorCode2);
Al.alBufferData(buffer, format, data, size, (int)frequency);
_soundIdentifier.Add(soundId, new SoundSource(buffer, path));
}
The issue is this line right here: System.Diagnostics.Debug.Assert(data != IntPtr.Zero));. When this line is not commented out, it always fails. I did have it work, and do not know what I did to change it, and it stopped working. I have posted about this on another post here: Load sound problem in OpenAL
I have looked all over, and from what I can gather, the issue is with the way that OpenAl is working on my system. To that end, I have uninstalled the Tao Framework that I am using to run OpenAl, and reinstalled. I have also done a system restore to as many points as I have back. I have thought about nuking my whole system, and starting fresh, but a want to avoid this if I can.
I Also have found this link http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html#ErrorHandling that has helped me understand more about Alut, but have been unable to get an alut.dll from it, and cannot get any errors to display. This code:
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
//System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
System.Diagnostics.Debug.Write(errorCode2);
Is my attempt to find out the exact error. If I write the code like:
int errorCode2 = Alut.alutGetError();
//string errorCodeString = Alut.alutGetErrorString(errorCode2);
System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
System.Diagnostics.Debug.Write(errorCode2);
I may be using the code all wrong to the find the exact error, as I am still learning c#.
Here is what I am looking for:
1)Is this a syntax error or an error with my system
2)If it is an error in my system, are there files that I am not removing when I try to do an uninstall of OpenAL to refresh all the files.
3)How do I get the alutGetError() code to display in such a way that I can actually read what it is.
Thank you for any help beforehand.
I recently ran into the same problem while going through that book and was able to figure it out by logging the error to the output window, notice I through the console.writeline in there.
After doing that I checked the output window which gave me the error code 519. After looking all over I saw a few forum posts recommending I re-install openAl to fix this issue which did the trick, all the links I found didn't work to the download so I had to hunt around but softTonic had the one that worked for me on my windows 7 machine http://openal.en.softonic.com/download
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
var error= Alut.alutGetError();
Console.WriteLine(error);
//System.Diagnostics.Debug.Assert(data != IntPtr.Zero);
Hope this helps,
helpdevelop
I would like to add some debug lines to my program. Once after executing statements it will record the current status to a file.
I have done that in following way.
public int? DoWork(int x, int y)
{
Log.Write("Received inputs. X an Y values are:"+x+","+y);
bool result = ChekData(x);
if (!result)
{
Log.Write("First input is not valid");
return null;
}
result = ChekData(y);
if (!result)
{
Log.Write("Second input is not valid");
return null;
}
Log.Write("Valid input found");
....
....
}
I feel this is not the standard wa to do this. Keeping text like this in the code. After searching I found using Resource file I can save these messages like name value pair.
But I have no idea about the standard of that. Please advise me.
Basicaly for the loging I am using Log4Net
This is pretty normal way of doing logging.
Using resource files for logging generally does not make sense because:
it moves descriptive message away from the place it most useful - inline code
logs most commonly used by original developers, so getting logs in Japanese (if log resource strings are properly localized) is rarely useful for English speaking developers and vise versa.
avoiding localization of some strings (one that are used for logging) may be inconvenient, localizing them is not free...
If it is only for debug purpose i would do the following:
Set appropriate debuglevels. The debug version should then be build using a level to show all messages. The release build normally don't need debug outputs. Therefore disable the message level for release output.
For distinction if you are in release build or debug build you can use the following 2 things:
#if DEBUG
// enable all tracing
#endif
or if you also want that your realease build brings messages if a Debugger is Attached
if(System.Diagnostics.Debugger.IsAttached)
{
// Someone has attached a debugger, so give more output
}
You can also wrap the logcalls if you want with a method which justs checks for debug/attached debugger..
I've made a console application which inserts data into a MySql backend, and reads the serial number from a hard disk
To do this i had to add References to MySql.Data and to System.Managment.
The way im running it is by copying the Debug directory from visual studio (i think this is the problem) and running the .exe file on the other machine.
When i run the application on another machine the stack trace error is:
PhDD >C:\Users\User\File\Indexer\WMI\Debug
Your key: 634685018347902535133
Exception getting SMART Object: reference not set to an instance of an object.
Exception in main thread: at System.ThrowHelper.ThrowArgumentOutOfRangeExcept
ion()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at WMITest.Menu.Run() in C:\Users\fps700\Music\WMITest\Menu.cs:line 49
Updated HDD Stats at28/03/2012 18:46:57
Am i correct in thinking this problem is because of the referencing ?
I've checked the methods by recompiling the same code on the other machine and it works, when the references are added through VS.
Can anyone guide me on how to resolve this issue ?
Cheers for reading.
P.S. i tried adding reference paths (by right clicking on the project, selecting options and then choosing Reference Paths and adding the two dll files)
Line 49
bool conversion = int.TryParse(smartData[1].ToString(), out temp);
After adding a fake int value just to make sure conversion isnt the error the new stack trace error is:
PhDD >C:\Users\bborisov\Dropbox\Indexer\WMI\Debug
Your key: 634685018347902535133
Exception getting SMART Object reference not set to an instance of an object.
Exception in main thread: at System.ThrowHelper.ThrowArgumentOutOfRangeExcept
ion()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at WMITest.Menu.Run() in C:\Users\fps700\Music\WMITest\Menu.cs:line 53
Updated HDD Stats at28/03/2012 19:00:24
line 53:
DBHandler.insertData(smartData[0].Trim(),
3, smartData[2], file.getKey());
Put code in to check validity of error situations which may be happening on the client pc but not the development one. You can handle the errors by either throwing an exception or handling it gracefully in a better way.
Here is the code which checks for error situations
if (smartData == null)
throw new Exception("Smart data is null; aborting");
if (smartData.Any() == false)
throw new Exception("Smart data instance is valid but has no elements; aborting");
bool conversion = int.TryParse(smartData[1].ToString(), out temp);