Line numbers in stack traces for UWP apps - c#

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

Related

CodecQuery.FindAllAsync crashes through try/catch when querying Audio codecs without subtype

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.

Xamarin Insights with line numbers

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);
}

COMException while adding paths to a ShellLibrary

I'm using Windows 7's Shell Libraries to overwrite an existing library and add new paths to it, using the managed wrapper available through the Windows API Code Pack 1.1.
Every now and then, I can't seem to reproduce this in any way, a COMException is thrown while adding the paths to the library:
System.Runtime.InteropServices.COMException (0x80070497): Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497)
at Microsoft.WindowsAPICodePack.Shell.IShellLibrary.Commit()
at ... (local code from here on out)
The code is quite straightforward. The error is thrown on the Add method.
using ( var activityContext = new ShellLibrary( LibraryName, true ) )
{
Array.ForEach( dataPaths, p => activityContext.Add( p.LocalPath ) );
}
Is there a certain scenario where this exception is to be expected which I can reproduce/test for?
Assuming this is a bug in the shell libraries, I could just catch the exception and retry doing the operation a couple of times, although I'm hoping for a cleaner 'solution'.

DbGeography.PointFromText error Exception has been thrown by the target of an invocation

I am starting my first project using spacial data. Im using VS 2012 and SQL 2012 I have referenced System.Data.Entity and can use DbGeography in my code but when I try to create a point I get the above error and don't understand why
here is my code
var text = string.Format(CultureInfo.InvariantCulture.NumberFormat,
"POINT({0} {1})", submitted.Long, submitted.Lat);
// 4326 is most common coordinate system used by GPS/Maps
try
{
var wkb = DbGeography.PointFromText(text, 4226);
}
catch (Exception exc)
{
}
the syntax that OP has used is correct, the actual issue that caused this error was the SRID, 4226 is not a known SRID, But you already knew this. because it is in your comment :)
A one line example of the correct usage in your scenario would be:
var wkb = DbGeography.PointFromText($"POINT({submitted.Long} {submitted.Lat})", 4326);
Where did you go wrong though? Whenever you get a
System.Reflection.TargetInvocationException
With a message of
Exception has been thrown by the target of an invocation
You must immediately check the Inner Exception for the details on the actual error, in this case it is outlined clearly for you:
24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view.
I realise that this is an old thread, but IMO this is an example of second most common .Net developer issue that people keep posting on SO. Please read through your full exception stack before pulling your hair out.
I'm just guessing, but I reckon NullReferenceException issues would be the most common :)
is wrong to order the lat and long
the correct is:
DbGeography.PointFromText(POINT(lat long), 4226);
Complete class:
public static DbGeography CreatePoint(double latitude, double longetude, int srid = 4326)
{
var lon = longetude.ToString(CultureInfo.InvariantCulture);
var lat = latitude.ToString(CultureInfo.InvariantCulture);
var geo = $"POINT({lat} {lon})";
return DbGeography.PointFromText(geo, srid);
}
Call:
CreatePoint(-46.55377, 23.11817)

Refrences break console app from running on other machines

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);

Categories

Resources