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

removed any attempt to handle ref assemblies via GAC when decompiling #1767

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 `<RunAnalyzers />` and `<RunAnalyzersDuringLiveAnalysis />` (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))
Expand Down
1 change: 0 additions & 1 deletion src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="System.Reactive" />
<PackageReference Include="ICSharpCode.Decompiler" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class DecompilationExternalSourceService : BaseExternalSourceService, IEx
private readonly Lazy<OmniSharpCSharpDecompiledSourceService> _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<OmniSharpCSharpDecompiledSourceService>(() => new OmniSharpCSharpDecompiledSourceService(omniSharpWorkspace.Services.GetLanguageServices(LanguageNames.CSharp), _loader, _loggerFactory));
_service = new Lazy<OmniSharpCSharpDecompiledSourceService>(() => new OmniSharpCSharpDecompiledSourceService(_loader, _loggerFactory));
}

public async Task<(Document document, string documentPath)> GetAndAddExternalSymbolDocument(Project project, ISymbol symbol, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -48,7 +46,7 @@ public class OmniSharpCSharpDecompiledSourceService
private readonly Lazy<MethodInfo> _metadataGetAssemblyInfo;
private readonly Lazy<MethodInfo> _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);
Expand All @@ -58,7 +56,6 @@ public OmniSharpCSharpDecompiledSourceService(HostLanguageServices provider, IAs
_metadataGetAssemblyInfo = _csharpMetadataAsSourceService.LazyGetMethod("GetAssemblyInfo");
_metadataGetAssemblyDisplay = _csharpMetadataAsSourceService.LazyGetMethod("GetAssemblyDisplay");

_provider = provider;
_loggerFactory = loggerFactory;
}

Expand All @@ -68,36 +65,11 @@ public async Task<Document> 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
Expand Down