Skip to content

Commit

Permalink
Merged PR 30060: Workaround runtime assembly loading bug
Browse files Browse the repository at this point in the history
See dotnet/runtime#83526

MEF uses the APIs affected to load assemblies.  To workaround the issue we pre-load all the assemblies we're adding to the MEF composition
  • Loading branch information
dibarbet committed Mar 16, 2023
2 parents 80c0b79 + 2e5e3a3 commit 8c008aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Immutable;
using System.Reflection;
using System.Runtime.Loader;
using Microsoft.CodeAnalysis.LanguageServer.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.Composition;
Expand All @@ -20,6 +21,16 @@ public static async Task<ExportProvider> CreateExportProviderAsync()
var assembliesToDiscover = Directory.EnumerateFiles(baseDirectory, "Microsoft.CodeAnalysis*.dll");
assembliesToDiscover = assembliesToDiscover.Concat(Directory.EnumerateFiles(baseDirectory, "Microsoft.ServiceHub*.dll"));

// Temporarily explicitly load the dlls we want to add to the MEF composition. This is due to a runtime bug
// in the 7.0.4 runtime where the APIs MEF uses to load assemblies break with R2R assemblies.
// See https://github.com/dotnet/runtime/issues/83526
//
// Once a newer version of the runtime is widely available, we can remove this.
foreach (var path in assembliesToDiscover)
{
Assembly.LoadFrom(path);
}

var discovery = PartDiscovery.Combine(
new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true), // "NuGet MEF" attributes (Microsoft.Composition)
new AttributedPartDiscoveryV1(Resolver.DefaultInstance));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!-- List of runtime identifiers that we want to publish an executable for -->
<RuntimeIdentifiers>win-x64;win-x86;win-arm64;linux-x64;linux-arm64;alpine-x64;alpine-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<!-- Publish ready to run executables when we're publishing platform specific executables. -->
<PublishReadyToRun Condition="'$(RuntimeIdentifier)' != '' Or '$(RestoreWithR2R)' == 'true'">true</PublishReadyToRun>
<PublishReadyToRun Condition="'$(RuntimeIdentifier)' != '' Or '$(RestoreWithR2R)' == 'true'">true</PublishReadyToRun>
</PropertyGroup>

<ItemGroup Label="Project References">
Expand Down

0 comments on commit 8c008aa

Please sign in to comment.