Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NullReferenceException' occurs when getting 'Microsoft.CodeAnalysis.TypeInfo' #35261

Closed
VasilievSerg opened this issue Apr 25, 2019 · 3 comments
Labels
Area-Compilers fabric-bot-test Testing the impact of changes to the fabric bot Need More Info The issue needs more information to proceed. Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Milestone

Comments

@VasilievSerg
Copy link

When using Microsoft.CodeAnalysis libraries, I faced a problem that when calling GetTypeInfo (extension method for SemanticModel), NullReferenceException occurs. The node for which a character is requested – ConstantPatternSyntax.

The used version is Microsoft.CodeAnalysis: 3.0.19.17001

Stack trace:

at Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyImplicitBuiltInConversionSlow(TypeSymbol source, TypeSymbol destination, HashSet`1& useSiteDiagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs:line 552
 at Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyBuiltInConversion(TypeSymbol source, TypeSymbol destination, HashSet`1& useSiteDiagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs:line 404
 at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoForNode(BoundNode lowestBoundNode, BoundNode highestBoundNode, BoundNode boundNodeForSyntacticParent) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs:line 2043
 at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetTypeInfoWorker(CSharpSyntaxNode node, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs:line 1142
 at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetTypeInfoWorker(CSharpSyntaxNode node, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs:line 310
 at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(PatternSyntax pattern, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs:line 844
 at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoFromNode(SyntaxNode node, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs:line 4644
 at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoCore(SyntaxNode node, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs:line 4713
 at Microsoft.CodeAnalysis.ModelExtensions.GetTypeInfo(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/Compilation/Extensions.cs:line 60

It also seems like the problem is reproduced in Visual Studio.

Visual Studio version: 16.0.2

class C1<T1, T2>
{
    void foo()
    {
        T1 val = default;
        if (val is null)
        {

        }
    }
}

If in this code you try to get TypeSymbol from ConstantPatternExpression (null) through Syntax Visualizer, Visual Studio will restart. In Event Viewer you can find a corresponding recording with description:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
   at Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyImplicitBuiltInConversionSlow(Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, System.Collections.Generic.HashSet`1<Microsoft.CodeAnalysis.DiagnosticInfo> ByRef)
   at Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyBuiltInConversion(Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, System.Collections.Generic.HashSet`1<Microsoft.CodeAnalysis.DiagnosticInfo> ByRef)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoForNode(Microsoft.CodeAnalysis.CSharp.BoundNode, Microsoft.CodeAnalysis.CSharp.BoundNode, Microsoft.CodeAnalysis.CSharp.BoundNode)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetTypeInfoWorker(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetTypeInfoWorker(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoFromNode(Microsoft.CodeAnalysis.SyntaxNode, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfoCore(Microsoft.CodeAnalysis.SyntaxNode, System.Threading.CancellationToken)
   at Roslyn.SyntaxVisualizer.Control.SyntaxVisualizerControl.TypeSymbolDetailsMenuItem_Click(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
@jcouv
Copy link
Member

jcouv commented Apr 26, 2019

Tagging @agocke
This is likely related to an issue he just fixed (PR #35249)

@jcouv jcouv added Area-Compilers Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. labels Apr 26, 2019
@jcouv
Copy link
Member

jcouv commented Jul 8, 2019

@VasilievSerg Would you be able to try this in 16.1 or later? I think this was fixed there already. Thanks

@gafter gafter added this to the Compiler.Next milestone Jul 9, 2019
@gafter gafter added the Need More Info The issue needs more information to proceed. label Sep 17, 2019
@ghost ghost added the fabric-bot-test Testing the impact of changes to the fabric bot label Aug 10, 2021
@ghost ghost closed this as completed Sep 15, 2021
@ghost
Copy link

ghost commented Sep 15, 2021

Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers fabric-bot-test Testing the impact of changes to the fabric bot Need More Info The issue needs more information to proceed. Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Projects
None yet
Development

No branches or pull requests

3 participants