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
Changes from 1 commit
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
1 change: 0 additions & 1 deletion src/OmniSharp.Roslyn.CSharp/OmniSharp.Roslyn.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -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" />
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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<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);
@@ -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<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