ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

NullReferenceException at Microsoft.ApplicationInsights.Extensibility.Implementation.GetStackFrame

Open abhimanyusinghal opened this issue 8 years ago • 1 comments

I am using Microsoft.ApplicationInsights in a .NET Core dll.

I am unable to create an Instance of ExceptionTelemetry as it throws a NullReferenceException.

Upon further investigation I found: On Xamarin Android the Exception contains a System.Diagnostics.StackFrame as " {< unknown method > at < unknown offset > in file:line:column :0:0} "

Following Method is throwing Exception: Microsoft.ApplicationInsights.Extensibility.Implementation.GetStackFrame

internal static External.StackFrame GetStackFrame(StackFrame stackFrame, int frameId)
        {
            var convertedStackFrame = new External.StackFrame()
            {
                level = frameId
            };

            var methodInfo = stackFrame.GetMethod();
            string fullName;
            if (methodInfo.DeclaringType != null)
            {
                fullName = methodInfo.DeclaringType.FullName + "." + methodInfo.Name;
            }
            else
            {
                fullName = methodInfo.Name;
            }

            convertedStackFrame.method = fullName;
            convertedStackFrame.assembly = methodInfo.Module.Assembly.FullName;
            convertedStackFrame.fileName = stackFrame.GetFileName();

            // 0 means it is unavailable
            int line = stackFrame.GetFileLineNumber();
            if (line != 0)
            {
                convertedStackFrame.line = line;
            }

            return convertedStackFrame;
        }

Exception raised from my code which I am trying to report to Application insights contains following stack trace: at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x00040] in D:\a\1\s\Xamarin.Forms.Xaml\CreateValuesVisitor.cs:50 at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000ac] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:149 at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:200 at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext) [0x00054] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:140 at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml) [0x00058] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:89 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0

Upon further investigration

Looks like on Xamarin Android, Stack Information contains lines which do not have method information and hence GetStackFrame is throwing an Exception.

Version Info

SDK Version : 2.5.1 .NET Version : .NET Standard 2.0 Xamarin Android Version: 8.2.0.16

abhimanyusinghal avatar May 28 '18 11:05 abhimanyusinghal

@abhimanyusinghal

Thanks for reporting the issue!

It seems to be caused by linker optimizations https://forums.xamarin.com/discussion/7017/argumentnullexception-when-linked-with-link-sdk-assemblies-only https://forums.xamarin.com/discussion/30645/bug-in-release-mode-system-argumentnullexception-argument-cannot-be-null-linker-problem.

lmolkova avatar Jun 07 '18 02:06 lmolkova