Open vsfeedback opened 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:
After reaching the "Open Roslyn.sln" step, you can do the following to debug this issue specifically:
InvalidCastException
If you have any questions or have trouble reproducing the issue in a debugger, let us know!
Hi, So the probles is here: ConvertEnumUnderlyingTypeToUInt64 in EnumUtilities.cs
value == 0
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.
Hello! I see that item still is not processed. Will it be fixed in next VS build? Thanks!
<source>Editor or Editor Extension</source>
<description>System.InvalidCastException: Specified cast is not valid.

at Roslyn.Utilities.EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(Object value, SpecialType specialType)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractFlagsEnumGenerator.CreateNonFlagsEnumConstantValue(INamedTypeSymbol enumType, Object constantValue)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ExpressionGenerator.GenerateExpression(ITypeSymbol type, Object value, Boolean canUseFieldReference)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ExpressionGenerator.GenerateExpression(ITypeSymbol type, Object value, Boolean canUseFieldReference)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GenerateEqualsValueClause(IParameterSymbol parameter, Boolean isExplicit, Boolean seenOptional)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GetParameter(IParameterSymbol p, CodeGenerationOptions options, Boolean isExplicit, Boolean isFirstParam, Boolean seenOptional)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GetParameters(IEnumerable`1 parameterDefinitions, Boolean isExplicit, CodeGenerationOptions options)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.ParameterGenerator.GenerateParameterList(IEnumerable`1 parameterDefinitions, Boolean isExplicit, CodeGenerationOptions options)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.MethodGenerator.GenerateMethodDeclarationWorker(IMethodSymbol method, CodeGenerationDestination destination, Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.MethodGenerator.GenerateMethodDeclaration(IMethodSymbol method, CodeGenerationDestination destination, Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.CreateMethodDeclaration(IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.GetNewMember(CodeGenerationOptions options, CodeGenerationDestination codeGenerationDestination, ISymbol member, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembersToEndOfDestination[TDeclarationSyntax](TDeclarationSyntax destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamedTypeGenerator.GenerateNamedTypeDeclaration(ICodeGenerationService service, INamedTypeSymbol namedType, CodeGenerationDestination destination, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.CreateNamedTypeDeclaration(INamedTypeSymbol namedType, CodeGenerationDestination destination, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.GetNewMember(CodeGenerationOptions options, CodeGenerationDestination codeGenerationDestination, ISymbol member, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembersToEndOfDestination[TDeclarationSyntax](TDeclarationSyntax destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, IList`1 availableIndices, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination, IEnumerable`1 members, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamespaceGenerator.GenerateNamespaceDeclaration(ICodeGenerationService service, INamespaceSymbol namespace, CodeGenerationOptions options, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.NamespaceGenerator.AddNamespaceTo(ICodeGenerationService service, CompilationUnitSyntax destination, INamespaceSymbol namespace, CodeGenerationOptions options, IList`1 availableIndices, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.AddNamespace[TDeclarationNode](TDeclarationNode destination, INamespaceSymbol namespace, CodeGenerationOptions options, IList`1 availableIndices, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.<>c__DisplayClass54_0.<AddNamespaceAsync>b__0(SyntaxNode t, CodeGenerationOptions opts, IList`1 ai, CancellationToken ct)
 at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.<GetEditAsync>d__39.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.MetadataAsSource.AbstractMetadataAsSourceService.<AddSourceToAsync>d__5.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.MetadataAsSource.MetadataAsSourceFileService.<GetGeneratedFileAsync>d__11.MoveNext()

--- End of stack trace from previous location where exception was thrown ---
 at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken)
 at Roslyn.Utilities.TaskExtensions.WaitAndGetResult[T](Task`1 task, CancellationToken cancellationToken)

at Microsoft.VisualStudio.LanguageServices.Implementation.VisualStudioSymbolNavigationService.TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet options, CancellationToken cancellationToken)
 at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.<>c.<TryNavigateToMetadataSymbol>b__6_0(ISymbol symbol, Project project, ISymbolNavigationService service)

at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateToMetadataSymbol(Workspace workspace, String symbolKey, Func`4 action)

at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateToMetadataSymbol(Workspace workspace, String symbolKey)

at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.TryNavigateTo(Workspace workspace, Boolean isPreview)

at Microsoft.CodeAnalysis.Editor.Host.IStreamingFindUsagesPresenterExtensions.<TryNavigateToOrPresentItemsAsync>d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionHelpers.TryGoToDefinition(ISymbol symbol, Project project, IEnumerable`1 streamingPresenters, CancellationToken cancellationToken, Boolean thirdPartyNavigationAllowed, Boolean throwOnHiddenDefinition)

at Microsoft.CodeAnalysis.Editor.GoToDefinition.AbstractGoToDefinitionService.TryGoToDefinition(Document document, Int32 position, CancellationToken cancellationToken)

at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionCommandHandler.TryExecuteCommand(Document document, Int32 caretPosition, IGoToDefinitionService goToDefinitionService, CommandExecutionContext context)

at Microsoft.CodeAnalysis.Editor.GoToDefinition.GoToDefinitionCommandHandler.ExecuteCommand(GoToDefinitionCommandArgs args, CommandExecutionContext context)

at Microsoft.VisualStudio.Commanding.CommandHandlerExtensions.ExecuteCommand[T](ICommandHandler commandHandler, T args, Action nextCommandHandler, CommandExecutionContext executionContext)

at Microsoft.VisualStudio.UI.Text.Commanding.Implementation.EditorCommandHandlerService.<>c__DisplayClass14_1`1.<Execute>b__1()

at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call)
--- End of stack trace from previous location where exception was thrown ---

at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)</description>
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.
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.
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.
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
Confirm! Easy to reproduce with Offreg.
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.
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.
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,
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:
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)