diff --git a/CHANGELOG.md b/CHANGELOG.md index fc374025e0..ecffca69f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All changes to the project will be documented in this file. +## [1.35.1] - not yet released +* Fixed not supported exception when trying to decompile a BCL assembly on Mono (PR: [#1767](https://github.com/OmniSharp/omnisharp-roslyn/pull/1767)) + ## [1.35.0] - 2020-04-10 * Support for `` and `` (PR: [#1739](https://github.com/OmniSharp/omnisharp-roslyn/pull/1739)) * Add `typeparam` documentation comments to text description ([omnisharp-vscode#3516](https://github.com/OmniSharp/omnisharp-vscode/issues/3516), PR: [#1749](https://github.com/OmniSharp/omnisharp-roslyn/pull/1749)) diff --git a/src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj b/src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj index 80997f7afb..2f38e3b5ce 100644 --- a/src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj +++ b/src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj @@ -18,7 +18,6 @@ - diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/DecompilationExternalSourceService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/DecompilationExternalSourceService.cs index cc99c3d2e5..33784aa0e0 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/DecompilationExternalSourceService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/DecompilationExternalSourceService.cs @@ -26,10 +26,10 @@ public class DecompilationExternalSourceService : BaseExternalSourceService, IEx private readonly Lazy _service; [ImportingConstructor] - public DecompilationExternalSourceService(IAssemblyLoader loader, ILoggerFactory loggerFactory, OmniSharpWorkspace omniSharpWorkspace) : base(loader) + public DecompilationExternalSourceService(IAssemblyLoader loader, ILoggerFactory loggerFactory) : base(loader) { _loggerFactory = loggerFactory; - _service = new Lazy(() => new OmniSharpCSharpDecompiledSourceService(omniSharpWorkspace.Services.GetLanguageServices(LanguageNames.CSharp), _loader, _loggerFactory)); + _service = new Lazy(() => new OmniSharpCSharpDecompiledSourceService(_loader, _loggerFactory)); } public async Task<(Document document, string documentPath)> GetAndAddExternalSymbolDocument(Project project, ISymbol symbol, CancellationToken cancellationToken) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/OmniSharpCSharpDecompiledSourceService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/OmniSharpCSharpDecompiledSourceService.cs index 5fd684c1b7..d4a4058ebf 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/OmniSharpCSharpDecompiledSourceService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Decompilation/OmniSharpCSharpDecompiledSourceService.cs @@ -23,7 +23,6 @@ using OmniSharp.Extensions; using System.IO; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Scripting; using OmniSharp.Services; using System.Reflection; using OmniSharp.Utilities; @@ -34,7 +33,6 @@ namespace OmniSharp.Roslyn.CSharp.Services.Decompilation { public class OmniSharpCSharpDecompiledSourceService { - private readonly HostLanguageServices _provider; private readonly ILoggerFactory _loggerFactory; private const string MetadataAsSourceHelpers = "Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceHelpers"; private const string CSharpDocumentationCommentFormattingService = "Microsoft.CodeAnalysis.CSharp.DocumentationComments.CSharpDocumentationCommentFormattingService"; @@ -48,7 +46,7 @@ public class OmniSharpCSharpDecompiledSourceService private readonly Lazy _metadataGetAssemblyInfo; private readonly Lazy _metadataGetAssemblyDisplay; - public OmniSharpCSharpDecompiledSourceService(HostLanguageServices provider, IAssemblyLoader loader, ILoggerFactory loggerFactory) + public OmniSharpCSharpDecompiledSourceService(IAssemblyLoader loader, ILoggerFactory loggerFactory) { _roslynFeatureAssembly = loader.LazyLoad(Configuration.RoslynFeatures); _csharpFeatureAssembly = loader.LazyLoad(Configuration.RoslynCSharpFeatures); @@ -58,7 +56,6 @@ public OmniSharpCSharpDecompiledSourceService(HostLanguageServices provider, IAs _metadataGetAssemblyInfo = _csharpMetadataAsSourceService.LazyGetMethod("GetAssemblyInfo"); _metadataGetAssemblyDisplay = _csharpMetadataAsSourceService.LazyGetMethod("GetAssemblyDisplay"); - _provider = provider; _loggerFactory = loggerFactory; } @@ -68,36 +65,11 @@ public async Task AddSourceToAsync(Document document, Compilation symb var containingOrThis = symbol.GetContainingTypeOrThis(); var fullName = GetFullReflectionName(containingOrThis); - string assemblyLocation = null; - var isReferenceAssembly = symbol.ContainingAssembly.GetAttributes().Any(attribute => attribute.AttributeClass.Name == nameof(ReferenceAssemblyAttribute) - && attribute.AttributeClass.ToNameDisplayString() == typeof(ReferenceAssemblyAttribute).FullName); - if (isReferenceAssembly) - { - try - { - var fullAssemblyName = symbol.ContainingAssembly.Identity.GetDisplayName(); - - var globalAssemblyCacheType = typeof(ScriptOptions).Assembly.GetType("Microsoft.CodeAnalysis.GlobalAssemblyCache"); - var instance = globalAssemblyCacheType.GetField("Instance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); - - var args = new object[] { fullAssemblyName, assemblyLocation, null, CultureInfo.CurrentCulture }; - instance.GetType().InvokeMember("ResolvePartialName", BindingFlags.InvokeMethod, Type.DefaultBinder, instance, args); - assemblyLocation = (string)args[1]; - } - catch (Exception) - { - // log - } - } - + var reference = symbolCompilation.GetMetadataReference(symbol.ContainingAssembly); + var assemblyLocation = (reference as PortableExecutableReference)?.FilePath; if (assemblyLocation == null) { - var reference = symbolCompilation.GetMetadataReference(symbol.ContainingAssembly); - assemblyLocation = (reference as PortableExecutableReference)?.FilePath; - if (assemblyLocation == null) - { - throw new NotSupportedException("Cannot_navigate_to_the_symbol_under_the_caret"); - } + throw new NotSupportedException("Cannot_navigate_to_the_symbol_under_the_caret"); } // Decompile