When running a Unity HoloLens program from Visual Studio, when an exception is thrown how do I get the line numbers in the stack trace? - visual-studio

Currently when an exception is thrown from within my Unity script while using my HoloLens the Debug Output in Visual Studio shows the stack trace without the line numbers.
How do I get the line numbers along with the stack trace? I'd be fine with it being logged somewhere else other than the Debug Output.
Here's some example output in Visual Studio:
Exception thrown: 'System.NullReferenceException' in Assembly-CSharp.dll
NullReferenceException: Object reference not set to an instance of an object.
at NewBehaviourScript.Update()
at NewBehaviourScript.$Invoke6Update(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: <Unknown> Line: 0)
And the corresponding Unity script (I made a Cube and attached a NewBehaviourScript component):
public class NewBehaviourScript : MonoBehaviour {
// Update is called once per frame
void Update ()
{
object a = null;
a.GetType();
}
}
I tried changing the build from Release to Debug doesn't give the line numbers.
I tried googling, and it looks like it's not showing the line numbers for others, as well: http://answers.unity3d.com/questions/1315985/null-reference-in-line-0.html
I tried asking on Microsoft's forums, but didn't receive any useful replies.

I don't think you would get the line number since it does not exist anymore. You get it in Unity editor because you are not running a full build of the application so Unity still has access to the non-compiled code. When you run on the device, it sends debug commands to the VS console about the printing and the errors but all the code is binary at that point, so there is no reason nor possibility to provide a line number.
Actually this is not specific to Hololens, but you would get the same in Android or iOS. Once build, the code is no longer the same, it does not even match one to one as the compiler performs optimizations.
What you can do is placed Debug commands to see where it happens.
public class NewBehaviourScript : MonoBehaviour {
// Update is called once per frame
void Update ()
{
object a = null;
#if DEBUG
if(a == null)
{
Debug.Log("[NewBehaviourScript] Running update with null a object");
}
#endif
a.GetType();
Debug.Log("[NewBeahviourScript] if this line prints, method did not crash");
}
}
In this example, you can use the DEBUG macros if you would have code running only for debug purpose. This way you can easily exclude it on export. The second call for Debug is not required in the macro since the build process will discard it when you set the build to Release or Master.

Related

Hitting exception when using Google Protobuf Any UnpackTo function in C++

google::protobuf::Any anyResponse = someResponse.response();
ResponseType unpackResp; //ResponseType is a subclass of google::protobuf::Message
if (anyResponse.UnpackTo(&unpackResp))
{
...
}
Running this piece of C++ code and access vialotion exception happens in anyResponse.UnpackTo(&unpackResp). Does someone know how to debug into this function? I checked anyResponse and it looks good.
It went through these files in google::protobuf:
call stack
Anyway I can see these files?

C++/CLI: Access violation when debugging/stepping into code in 32-bit (VS-2015)

I got this strange issue when stepping into code when debugging a 32-bit mixed mode assembly. The stripped down version of the code looks like this:
public ref class FooClass {
public:
FooClass();
};
FooClass::FooClass(){
// Note: doesn't matter what code is in here, as long as it is native
char test[10];
memset((void*)test, 0, sizeof(test));
}
This class is then instantiated in another class:
FooClass^ BarClass::Test() {
FooClass^ addr = gcnew FooClass();
return addr;
}
..which again is instantiated in a C# console app:
class Program
{
static void Main(string[] args)
{
BarClass bar = new BarClass();
FooClass foo = bar.Test();
}
}
When stepping through the code, and into the FooClass constructor, I get an exception
(note: removed argument info for the sake of less mess):
ntdll.dll!_NtTraceEvent#16() Unknown
ntdll.dll!EtwpEventWriteFull() Unknown
ntdll.dll!_EtwEventWrite#20() Unknown
clrjit.dll!Compiler::lvaInitTypeRef() Line 253 C++
clrjit.dll!Compiler::compCompileHelper(...) Line 3489 C++
clrjit.dll!Compiler::compCompile(...) Line 3092 C++
clrjit.dll!jitNativeCode(...) Line 4063 C++
clrjit.dll!CILJit::compileMethod(...) Line 180 C++
[Managed to Native Transition]
> FooBar.dll!FooBar::BarClass::Test() Line 16 C++
ConsoleApp.exe!ConsoleApp.Program.Main(string[] args) Line 15 C#
However, if I just add breakpoints in the constructors and just run to next breakpoint, the code runs fine.
Also, when removing native code, it runs fine.
This issue does not occur in 64-bit mode. I crosschecked for settings, but can't really see anything special.
There are no 3rd party dll's, all the native code is compiled into the assembly.
This is not my first C++/CLI project, but first time I do it in VS2015.
From the comments in my original question, the following was suggested:
Enter Tools -> Options -> Debugging -> General
Enable the "Use Managed Compatibility Mode" checkbox
This fixed the issue.
In my case the issue was an exception in an internal managed component, that apparently did not propagate well to the native layer that invoked it - and manifested as exactly this impossible ETW stack.
To debug I had to attach as managed-only. The exception was staring me right in the face (missing DLL, but that's irrelevant).
Hope this helps someone out there.

MissingMetadataException when building UWP app with .Net native

I have this UWP app that uses a project (UWP class library) which itself uses EF7 and SQLite.
I tried to build the app in the Release mode using .Net native tool chain, the build completes successfully (after a good long time, and after eating as much memory as it can), but the application crashes just after leaving the splash screen.
After following some advice on SO I tried the .Net native with Debug mode, the build finishes just like in the Release mode, but I get many errors on the output window and it is the same scenario as this one UWP - .NET Native tool chain compilation error
I followed #Matt Whilden advice, and I got rid of those errors, then tried again.
This time I got hit by this famous MissingMetadataException :
The output window shows this :
Exception thrown: 'System.AggregateException' in System.Private.Threading.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
The thread 0x2a30 has exited with code 0 (0x0).
Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.Reflection.Core.dll
Additional information: 'Microsoft.Extensions.Caching.Memory.MemoryCacheOptions' is missing
metadata. For more information, please visit
http://go.microsoft.com/fwlink/?LinkID=392859
I tried to follow my code, during execution and I found out that it is caused by the first ever call to a DbSet table from my DbContext
public long GetLastTimeStamp()
{
//-----> Here is the line causing the error
var sortedArticles = DbContext.Articles.OrderByDescending(article => article.ArticlePubDate).ToList();
if (sortedArticles != null && sortedArticles.Count != 0)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
TimeSpan elapsedTime = sortedArticles.First().ArticlePubDate - epoch;
return (long)elapsedTime.TotalSeconds;
}
else
{
return 0;
}
}
This method above is called inside an Async method, just to know.
I tried, desperately, to call .ToList() by doing :
var sortedArticles = DbContext.Articles.ToList().OrderByDescending(article => article.ArticlePubDate).ToList();
But still get the same error.
This is really frustrating, I don't know how to solve this problem, not sure what and how I should change the Default.rd.xml, any one can help telling me how to achieve this build correctly ?
Please try to add type 'Microsoft.Extensions.Caching.Memory.MemoryCacheOptions' in Default.rd.xml (already present in your project).
cf. https://blogs.msdn.microsoft.com/dotnet/2014/05/21/net-native-deep-dive-help-i-hit-a-missingmetadataexception/
For example:
<?xml version="1.0" encoding="utf-8"?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Type Name="Microsoft.Extensions.Caching.Memory.MemoryCacheOptions" Dynamic="Required All" />
</Application>
</Directives>

Editing in Telerik RadGrid

I'm working off of the following example to implement editing of a cell in my grid when the cell is clicked:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultcs.aspx
I'd like it to work just like in the example, but based on a single-click. I can't get it to work as I keep getting the following error buried away in Telerik.Web.UI.WebResource:
0x800a139e - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The string was not recognized as a valid format.
If anyone can lend any assistance, I will you owe you my first-born, as I am pulling my hair out trying to get this to work.
Thank you
Initially, the error was here but it didn't seem essential:
protected void detailsGrid_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem && e.Item.IsInEditMode)
{
((e.Item as GridDataItem)["detailsGridMonthOneCol"].Controls[0] as RadNumericTextBox).Width = Unit.Pixel(50); // ArgumentOutOfRangeException - Specified argument was out of the range of valid values
}
}
detailsGridMonthOneCol is the name of the column I double-clicked. This didn't seem essential, so I commented it out and that's when I got the following error:
Unhandled exception at line 15, column 16485 in http://localhost:63919/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=;;System.Web.Extensions,+Version=4.0.0.0,+Culture=neutral,+PublicKeyToken=31bf3856ad364e35:en-US:10a773fc-9022-49ec-acd6-8830962d8cbb:ea597d4b:b25378d2;Telerik.Web.UI,+Version=2012.2.815.40,+Culture=neutral,+PublicKeyToken=121fae78165ba3d4:en-US:bd12f06c-2391-4523-868e-0017245d9792:16e4e7cd:ed16cbdc:f7645509:24ee1bba:e330518b:1e771326:8e6f0d33:6a6d718d:58366029:4b09f651:a2c5be80:874f8ea2:c172ae1e:f46195d3:9cdfc6e7:2003d0b8:c8618e41:e4f8f289
0x800a139e - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The string was not recognized as a valid format.
The code is buried away but here's where the exception gets thrown:
var e=this._get_eventHandlerList().getHandler("endRequest"),b=false;if(e){var c=new Sys.WebForms.EndRequestEventArgs(a,f?f.dataItems:{},d);e(this,c);b=c.get_errorHandled()}if(a&&!b)throw a}
In your Script Manager add a handler to the OnAsyncPostBackError="myScriptManager_AsyncPostBackError" and in code behind just put one breakpoint on the open curly brace of the method.
protected void myScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{ // breakpoint this line.
}
doing this, probaly, this breakpoint will be hit and you could debug your code, and inspect who was thwrowing the exception.
This can help, but, the only way to help you, in fact, is if you provide the full source code. I suggest you to create another project, isolate the code that you want to work, and publish this code on github, ftp, etc.
Please, post your code and i will help.
The code is not really buried away. Javascript is showing you this error. However. the error is happening on the server side (Sys.WebForms.PageRequestManagerServerErrorException)
Check the Event Viewer (start => Run => eventvwr) it will show you more details of the error.

Pointer object Creates a windows error in Visual C++ 6.0

I will paste a code snippet and explain the problem I am facing,
void materialPropertiesDlg::OnNext() {
contiBeam *continousBeamPtr;
contiBeam contiBeamObj;
UpdateData(TRUE);
switch (m_steel_grade) {
// Do Something
}
continousBeamPtr->setMaterial(m_conc_grade, m_steel_grade);
OnOK();
}
As you see, in line 2 a pointer object is created and in the next line an object is created. So, then I call the member function setMaterials() of the class contiBeam. I can easily do that with the object contiBeamObj, but when I call the function using contiBeamPointer, the windows throws an error which reads
Application Has Stopped working.
I am able to do the needful, I just want to know what could be the possible reason for this?
You are using your pointer contiBeam *continousBeamPtr; without having allocated it.
That is Undefined Behaviour and will make your application crash.
You should allocate (reserve memory for) your pointer by using new, like so:
contiBeam *continousBeamPtr = new contiBeam;
However, the ultimate question is, why are you using a pointer in the first place? Do you need one? Doesn't look like it from the code you posted.

Resources