From 2e5e3a3a7c0a92dce55de28b934eecd73a3c92f7 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 16 Mar 2023 14:43:55 -0700 Subject: [PATCH] Workaround runtime bug in 7.0.4 where MEF assembly load APIs fail --- .../ExportProviderBuilder.cs | 11 +++++++++++ .../Microsoft.CodeAnalysis.LanguageServer.csproj | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs index cb87eceea2299..c924069a54170 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs @@ -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; @@ -20,6 +21,16 @@ public static async Task 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)); diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj index bffb24e4602a5..99f1d0d777520 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj @@ -37,7 +37,7 @@ win-x64;win-x86;win-arm64;linux-x64;linux-arm64;alpine-x64;alpine-arm64;osx-x64;osx-arm64 - true + true