You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Microsoft.CodeAnalysis.VisualBasic.SymbolDisplay.ToDisplayString to generate VB declarations from dll files and xml files in my API docs. I found that Microsoft.CodeAnalysis.VisualBasic.SymbolDisplayVisitor.AddMethodName throws System.InvalidOperationException: Unexpected value 'Destructor' of type 'Microsoft.CodeAnalysis.MethodKind' when converting C# destructor ISymbol to string by calling SymbolDisplay.ToDisplayString.
ImportsSystem.IOImportsMicrosoft.CodeAnalysisImportsCS=Microsoft.CodeAnalysis.CSharpImportsVB=Microsoft.CodeAnalysis.VisualBasicModuleProgramSubMain()' Create C# code that overrides the Finalize methodDimcsharpCodeAsString= "
usingSystem;
publicclassExample{
~Example(){}}"
' Compile the C# codeDimcompilation=CreateCompilationFromCSharpCode(csharpCode,"FinalizeExample")' Get the symbol for the Finalize methodDimexampleClass=compilation.GetTypeByMetadataName("Example")DimmethodSymbol=exampleClass.GetMembers().OfType(OfIMethodSymbol)().First()' Create a VB symbol display formatDimformat=SymbolDisplayFormat.FullyQualifiedFormat' Display the symbol using VB SymbolDisplayDimformattedSymbol=VB.SymbolDisplay.ToDisplayString(methodSymbol,format)Console.WriteLine("Method signature in VB format:")Console.WriteLine(formattedSymbol)EndSubPublicFunctionCreateCompilationFromCSharpCode(codeAsString,nameAsString,ParamArrayreferencesAsMetadataReference())AsCompilationDimparserOptionAsNewCS.CSharpParseOptionsDimsyntaxTree=CS.CSharpSyntaxTree.ParseText(code,parserOption)ReturnCS.CSharpCompilation.Create(name,options:=NewCS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,xmlReferenceResolver:=XmlFileResolver.Default),syntaxTrees:={syntaxTree},references:=GetDefaultMetadataReferences().Concat(If(references,Array.Empty(OfMetadataReference))))EndFunctionPrivateFunctionGetDefaultMetadataReferences()AsIEnumerable(OfMetadataReference)DimdirPath=Path.GetDirectoryName(GetType(Object).Assembly.Location)ReturnFromdllInDirectory.EnumerateFiles(dirPath,"*.dll",SearchOption.TopDirectoryOnly)SelectMetadataReference.CreateFromFile(dll)EndFunctionEndModule
Run the project.
Diagnostic Id:
N/A
Expected Behavior:
The program produces the following output:
Method signature in VB format:Protected Overrides Sub Finalize()
Actual Behavior:
The program produces the following output and crashed:
Unhandled exception. System.InvalidOperationException: Unexpected value 'Destructor' of type 'Microsoft.CodeAnalysis.MethodKind' at Microsoft.CodeAnalysis.VisualBasic.SymbolDisplayVisitor.AddMethodName(IMethodSymbol symbol) at Microsoft.CodeAnalysis.VisualBasic.SymbolDisplayVisitor.VisitMethod(IMethodSymbol symbol) at Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.MethodSymbol.Accept(SymbolVisitor visitor) at Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol.Microsoft.CodeAnalysis.ISymbol.Accept(SymbolVisitor visitor) at Microsoft.CodeAnalysis.VisualBasic.SymbolDisplay.PopulateDisplayParts(ArrayBuilder`1 builder, ISymbol symbol, SemanticModel semanticModelOpt, Int32 positionOpt, SymbolDisplayFormat format, Boolean minimal) at Microsoft.CodeAnalysis.VisualBasic.SymbolDisplay.ToDisplayString(ISymbol symbol, SemanticModel semanticModel, Int32 position, SymbolDisplayFormat format, Boolean minimal) at Microsoft.CodeAnalysis.VisualBasic.SymbolDisplay.ToDisplayString(ISymbol symbol, SymbolDisplayFormat format) at VbSymbolDisplayFinalize.Program.Main()
The text was updated successfully, but these errors were encountered:
I use
Microsoft.CodeAnalysis.VisualBasic.SymbolDisplay.ToDisplayString
to generate VB declarations from dll files and xml files in my API docs. I found thatMicrosoft.CodeAnalysis.VisualBasic.SymbolDisplayVisitor.AddMethodName
throwsSystem.InvalidOperationException: Unexpected value 'Destructor' of type 'Microsoft.CodeAnalysis.MethodKind'
when converting C# destructor ISymbol to string by callingSymbolDisplay.ToDisplayString
.Version Used:
4.13.0
Steps to Reproduce:
Create a VB console project
VbSymbolDisplayCsOptional.vbproj
Edit
Program.vb
Program.vb
Run the project.
Diagnostic Id:
N/A
Expected Behavior:
The program produces the following output:
Actual Behavior:
The program produces the following output and crashed:
The text was updated successfully, but these errors were encountered: