dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.84k stars 4k forks source link

VS crashes on some methods when colling the intellicense. #23516

Open vsfeedback opened 6 years ago

vsfeedback commented 6 years ago

After calling the intellicens by the mouse - VS crashes.

The assembly with the problematic method came from Nuget.

Unfortunately this is all I can say. the attached video ends immediatyly after method highlighting as VS is crashed,

CLR: Managed code called FailFast, saying "System.InvalidCastException: Specified cast is not valid.
   at Roslyn.Utilities.EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(Object value, SpecialType specialType)
   at Microsoft.CodeAnalysis.SymbolDisplay.AbstractSymbolDisplayVisitor.AddFlagsEnumConstantValue(INamedTypeSymbol enumType, Object constantValue, ArrayBuilder`1 allFieldsAndValues, ArrayBuilder`1 usedFieldsAndValues, Boolean preferNumericValueOrExpandedFlags)
   at Microsoft.CodeAnalysis.SymbolDisplay.AbstractSymbolDisplayVisitor.AddFlagsEnumConstantValue(INamedTypeSymbol enumType, Object constantValue, Boolean preferNumericValueOrExpandedFlags)
   at Microsoft.CodeAnalysis.SymbolDisplay.AbstractSymbolDisplayVisitor.AddEnumConstantValue(INamedTypeSymbol enumType, Object constantValue, Boolean preferNumericValueOrExpandedFlags)
   at Microsoft.CodeAnalysis.SymbolDisplay.AbstractSymbolDisplayVisitor.AddNonNullConstantValue(ITypeSymbol type, Object constantValue, Boolean preferNumericValueOrExpandedFlagsForEnum)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.AddConstantValue(ITypeSymbol type, Object constantValue, Boolean preferNumericValueOrExpandedFlagsForEnum)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.VisitParameter(IParameterSymbol symbol)
   at Microsoft.CodeAnalysis.CSharp.Symbols.ParameterSymbol.Accept(SymbolVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.AddParametersIfRequired(Boolean hasThisParameter, Boolean isVarargs, ImmutableArray`1 parameters)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.AddParameters(IMethodSymbol symbol)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.VisitMethod(IMethodSymbol symbol)
   at Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol.Accept(SymbolVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplay.ToDisplayParts(ISymbol symbol, SemanticModel semanticModelOpt, Int32 positionOpt, SymbolDisplayFormat format, Boolean minimal)
   at Microsoft.CodeAnalysis.CSharp.SymbolDisplay.ToMinimalDisplayParts(ISymbol symbol, SemanticModel semanticModel, Int32 position, SymbolDisplayFormat format)
   at Microsoft.CodeAnalysis.CSharp.Symbol.Microsoft.CodeAnalysis.ISymbol.ToMinimalDisplayParts(SemanticModel semanticModel, Int32 position, SymbolDisplayFormat format)
   at Microsoft.CodeAnalysis.Editor.CSharp.LanguageServices.CSharpSymbolDisplayService.ToMinimalDisplayParts(SemanticModel semanticModel, Int32 position, ISymbol symbol, SymbolDisplayFormat format)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.ToMinimalDisplayParts(ISymbol symbol, SymbolDisplayFormat format)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.AddDescriptionForMethod(IMethodSymbol method)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.<AddDescriptionPartAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.<AddPartsAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.<BuildDescriptionSectionsAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.LanguageServices.AbstractSymbolDisplayService.<ToDescriptionGroupsAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo.AbstractSemanticQuickInfoProvider.<CreateContentAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo.AbstractSemanticQuickInfoProvider.<BuildContentAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo.AbstractQuickInfoProvider.<GetQuickInfoItemAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo.AbstractQuickInfoProvider.<GetItemAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo.Controller.<ComputeModelInBackgroundAsync>d__9.MoveNext()
eax=00000000 ebx=ffffff00 ecx=00000004 edx=00000000 esi=776f9440 edi=776f9440
eip=77971fdc esp=2817cf2c ebp=2817cf60 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
ntdll!NtTerminateProcess+0xc:
77971fdc c20800          ret     8
0:069&gt; gn
       ^ No runnable debuggees error in 'gn'
0:069&gt; g
       ^ No runnable debuggees error in 'g'
0:069&gt; g
       ^ No runnable debuggees error in 'g'
0:069&gt; g
       ^ No runnable debuggees error in 'g'

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/157548/vs-crashes-on-some-methods-when-colling-the-intell.html VSTS ticketId: 530799 These are the original issue comments:

Dmytro Lisovyk on ‎11‎/‎29‎/‎2017, 05:43 AM (2 days ago):

The same problem on my PC!

Sam Harwell [MSFT] on ‎11‎/‎30‎/‎2017, 08:37 AM (24 hours ago):

Thank you for your feedback! For us to investigate this further, could you please provide a sample project to reproduce this issue. We look forward to hearing from you!


Hi Dmytro,


I didn't see any obvious bug in the code to make this happen. Before I spend a bunch of time testing things semi-randomly, I was hoping you could help me out with the following:


  1. The name of the NuGet package where the problem appears
  2. A sample source code file showing the use of this NuGet package, with a comment pointing out the line where I can hover (quick info) to cause the crash


Thank you,

Sam Harwell


Dmytro Oleksandrovych Baranovskyi on ‎12‎/‎1‎/‎2017, 02:01 AM (6 hours ago):

Unfortunately, this is the production code, so I cannot share it.

All I can say that this an extension method with a long generic signature which is defined in the referenced assembly. Nuget is not required, as we already tested.

I see that the problem is in roslyn. If you provide me the code sample how to run (AddDescriptionForMethod(IMethodSymbol method)) for the extension method in the referenced library. I ll debug the roslyn and send you the info what is going on.

Dmytro Oleksandrovych Baranovskyi on ‎12‎/‎1‎/‎2017, 02:09 AM (6 hours ago):

So, let's assume that we'got next:

Assembly A1 with type T1
Assembly B1 with static class which contains the class C which implements some extension method for T1
Executable E with references the A1, B1.

T1 t = new T1()
t.MyExtensionMethodWhichCrashesVS(); // :)

So, how to run the Roslyn on that one?

These are the original issue solutions: (no solutions)

sharwell commented 6 years ago

Hi Dmytro,

This repository is the one most likely containing the bug you found. The steps to get started with debugging it can be found here:

https://github.com/dotnet/roslyn/blob/master/docs/contributing/Building,%20Debugging,%20and%20Testing%20on%20Windows.md#developing-with-visual-studio-2017

After reaching the "Open Roslyn.sln" step, you can do the following to debug this issue specifically:

  1. Open the Debug → Windows → Exception Settings window
  2. Check the box for InvalidCastException
  3. Set the startup project to VisualStudioSetup.Next
  4. Press F5 to build and launch the solution for debugging

If you have any questions or have trouble reproducing the issue in a debugger, let us know!

mrbaranovskiy commented 6 years ago

Hi, So the probles is here: ConvertEnumUnderlyingTypeToUInt64 in EnumUtilities.cs

value == 0

https://github.com/dotnet/roslyn/blob/f67f002cfc8bf4e6f6447c0949e79c201f6e2bb6/src/Compilers/Core/Portable/InternalUtilities/EnumUtilties.cs#L38-L39

value cannot be cast directly, So looks like you need some return (unit)(int)value I 'm not familiar with the Roslyn source code, so you may be you will find the better solution. If you need additional info, don't hesitate to ask.

mrbaranovskiy commented 6 years ago

Hello! I see that item still is not processed. Will it be fixed in next VS build? Thanks!

sungam3r commented 6 years ago
Error
<source>Editor or Editor Extension</source>
<description>System.InvalidCastException: Specified cast is not valid.&#x000D;&#x000A;  
at Roslyn.Utilities.EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(Object value, SpecialType specialType)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractFlagsEnumGenerator.CreateNonFlagsEnumConstantValue(INamedTypeSymbol enumType, Object constantValue)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ExpressionGenerator.GenerateExpression(ITypeSymbol type, Object value, Boolean canUseFieldReference)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ExpressionGenerator.GenerateExpression(ITypeSymbol type, Object value, Boolean canUseFieldReference)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GenerateEqualsValueClause(IParameterSymbol parameter, Boolean isExplicit, Boolean seenOptional)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GetParameter(IParameterSymbol p, CodeGenerationOptions options, Boolean isExplicit, Boolean isFirstParam, Boolean seenOptional)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GetParameters(IEnumerable`1 parameterDefinitions, Boolean isExplicit, CodeGenerationOptions options)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GenerateParameterList(IEnumerable`1 parameterDefinitions, Boolean isExplicit, CodeGenerationOptions options)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.MethodGenerator.GenerateMethodDeclarationWorker(IMethodSymbol method, CodeGenerationDestination destination, Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.MethodGenerator.GenerateMethodDeclaration(IMethodSymbol method, CodeGenerationDestination destination, Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.CreateMethodDeclaration(IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.GetNewMember(CodeGenerationOptions options, CodeGenerationDestination codeGenerationDestination, ISymbol member, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembersToEndOfDestination[TDeclarationSyntax](TDeclarationSyntax destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamedTypeGenerator.GenerateNamedTypeDeclaration(ICodeGenerationService service, INamedTypeSymbol namedType, CodeGenerationDestination destination, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.CreateNamedTypeDeclaration(INamedTypeSymbol namedType, CodeGenerationDestination destination, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.GetNewMember(CodeGenerationOptions options, CodeGenerationDestination codeGenerationDestination, ISymbol member, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembersToEndOfDestination[TDeclarationSyntax](TDeclarationSyntax destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamespaceGenerator.GenerateNamespaceDeclaration(ICodeGenerationService service, INamespaceSymbol namespace, CodeGenerationOptions options, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamespaceGenerator.AddNamespaceTo(ICodeGenerationService service, CompilationUnitSyntax destination, INamespaceSymbol namespace, CodeGenerationOptions options, IList`1 availableIndices, CancellationToken cancellationToken)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.AddNamespace[TDeclarationNode](TDeclarationNode destination, INamespaceSymbol namespace, CodeGenerationOptions options, IList`1 availableIndices, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.&lt;&gt;c__DisplayClass54_0.&lt;AddNamespaceAsync&gt;b__0(SyntaxNode t, CodeGenerationOptions opts, IList`1 ai, CancellationToken ct)&#x000D;&#x000A;   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.&lt;GetEditAsync&gt;d__39.MoveNext()&#x000D;&#x000A;
--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.MetadataAsSource.AbstractMetadataAsSourceService.&lt;AddSourceToAsync&gt;d__5.MoveNext()&#x000D;&#x000A;--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#x000D;&#x000A;   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)&#x000D;&#x000A;   at Microsoft.CodeAnalysis.Editor.Implementation.MetadataAsSource.MetadataAsSourceFileService.&lt;GetGeneratedFileAsync&gt;d__11.MoveNext()&#x000D;&#x000A;
--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken)&#x000D;&#x000A;   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult[T](Task`1 task, CancellationToken cancellationToken)&#x000D;&#x000A;  
at Microsoft.VisualStudio.LanguageServices.Implementation.VisualStudioSymbolNavigationService.TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet options, CancellationToken cancellationToken)&#x000D;&#x000A;   at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.&lt;&gt;c.&lt;TryNavigateToMetadataSymbol&gt;b__6_0(ISymbol symbol, Project project, ISymbolNavigationService service)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateToMetadataSymbol(Workspace workspace, String symbolKey, Func`4 action)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateToMetadataSymbol(Workspace workspace, String symbolKey)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateTo(Workspace workspace, Boolean isPreview)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.Editor.Host.IStreamingFindUsagesPresenterExtensions.&lt;TryNavigateToOrPresentItemsAsync&gt;d__0.MoveNext()&#x000D;&#x000A;
--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   
at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionHelpers.TryGoToDefinition(ISymbol symbol, Project project, IEnumerable`1 streamingPresenters, CancellationToken cancellationToken, Boolean thirdPartyNavigationAllowed, Boolean throwOnHiddenDefinition)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.Editor.GoToDefinition.AbstractGoToDefinitionService.TryGoToDefinition(Document document, Int32 position, CancellationToken cancellationToken)&#x000D;&#x000A;   
at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionCommandHandler.TryExecuteCommand(Document document, Int32 caretPosition, IGoToDefinitionService goToDefinitionService, CommandExecutionContext context)&#x000D;&#x000A;  
at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionCommandHandler.ExecuteCommand(GoToDefinitionCommandArgs args, CommandExecutionContext context)&#x000D;&#x000A;   
at Microsoft.VisualStudio.Commanding.CommandHandlerExtensions.ExecuteCommand[T](ICommandHandler commandHandler, T args, Action nextCommandHandler, CommandExecutionContext executionContext)&#x000D;&#x000A;   
at Microsoft.VisualStudio.UI.Text.Commanding.Implementation.EditorCommandHandlerService.&lt;&gt;c__DisplayClass14_1`1.&lt;Execute&gt;b__1()&#x000D;&#x000A;   
at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call)&#x000D;&#x000A;--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)</description>

SteppeHunter commented 6 years ago

Unfortunately, faced the same problem.

I have method with signature like that: Task<Contract> GetClientInfoAsync(string contract, ProcessingType processingType = ProcessingType.MMM);

The second param is simple enum like that:

  public enum ProcessingType : byte
  {
    MMM,
    BBB,
    EXTERNAL,
  }

And when i just hower mouse to code string like that: var contract = await _service.GetClientInfoAsync(dbContract.IssueContract, (ProcessingType)dbContract.ProcessingType);

-> Visual Studio crashes!!!

This freaks me out, I have to skip some lines of code like minefields.

mrbaranovskiy commented 6 years ago

The problematic code-place in our case was public void TestMethod(SomeEnumType type = 0) and we fixed it by changing to public void TestMethod(SomeEnumType type = SomeEnumType.DefaultValue)

Look at the post I've mentioned about. Probably you need to play around with changing the enum inherithed type to from byte int and use explicit conversion where it is possible.

sharwell commented 6 years ago

I'm still not able to reproduce this. I tried the following code:

class MyType
{
    public void Method(MyEnum value = 0)
    {
        Method(value: (MyEnum)1);
    }
}

public enum MyEnum : byte
{
    Default = 1
}

If someone could create a self-contained example of the problem, it would be enormously helpful in creating a regression test to ensure the bug is corrected and does not reappear.

lasssard commented 6 years ago

Hi sharwell, I could reproduce that, with OffregLib (https://www.nuget.org/packages/OffregLib/). Also please install nuget package: Microsoft.VisualStudio.Setup.Configuration.Interop Please compile this code and move your mouse over: ork.CreateSubKey(@"blablabla"); method or try to write something after "blablalbla" and coma.

using System;
using Microsoft.VisualStudio.Setup.Configuration;
using OffregLib;

namespace ConsoleApp1
{
    internal class VSInstanceIdProvider
    {
        public void GetInter()
        {
            var instanceId = GetInstanceId();
            using (OffregHive hive = OffregHive.Open(string.Format(@"{0}\Microsoft\VisualStudio\15.0_{1}\privateregistry.bin", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), instanceId)))
            {
                string fullName = hive.Root.FullName;
                OffregKey ork = hive.Root.OpenSubKey(string.Format(@"Software\Microsoft\VisualStudio\15.0_{0}_Config", instanceId));
                ork.CreateSubKey(@"blablabla");
            }
        }

        private string GetInstanceId()
        {
            var query = new SetupConfiguration();
            var e = query.EnumAllInstances();

            var instances = new ISetupInstance[1];

            e.Next(1, instances, out _);
            return instances[0].GetInstanceId();
        }
    }
}

Visual Studio 2017 Pro v.15.7.3

Cheers, L

mrbaranovskiy commented 6 years ago

Confirm! Easy to reproduce with Offreg.

CyrusNajmabadi commented 4 years ago

Changing area to compiler. I was able to repro this. The issue is that we have an enum symbol whose underlying type is uint, but whose value is an int.

Note: it would be easy to update the code that is crashing to be resilient to this (and i'm creating a PR for that). but someone on the compiler should look to see what's going on here and if this is bug in the metadata level that needs fixing.

CyrusNajmabadi commented 4 years ago

i.e. we have this code (in SymbolDisplayVisitor):

            var underlyingSpecialType = enumType.EnumUnderlyingType.SpecialType;
            var constantValueULong = EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(constantValue, underlyingSpecialType);

underlyingSpecialType is uint, whereas constantValue is 0 (int). constantValue comes from the ExplicitDefaultValue of a parameter here:

                    AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue);

The parmaeter's type is OffregLib.RegOption, and the ExplicitDefaultValue is 0.

--

So, as above, these are either normal values and the helper function needs to be ok with them. Or they're bogus values, and something lower lever has created them. Not sure which. Need comiler insight here.