System.MissingMethodException: Method not found: 'Microsoft.Extensions.Hosting.IHostBuilder Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.ConfigureAppConfiguration
まだ誰も着手していません。
評価
調査の方向性
PluginAssemblyLoadContext の実装と、issue に示されている reflection ベースのエントリーポイント呼び出しから始めます。プラグインの依存関係ディレクトリと既定のコンテキストが Microsoft.Extensions.Hosting アセンブリをどのように解決するかを調べ、その後、起動パスを再現します。報告された MissingMethodException が発生せず、reflection 経由でプラグインが起動すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I have two webapi programs (Main and Plugin) both developed using net9. To facilitate startup, I use the Main program and start the Plugin program through reflection. However, this error keeps occurring during startup. For the dependent programs, the versions of my two programs are the same.
// This is a collectible (unloadable) AssemblyLoadContext that loads the dependencies
// of the plugin from the plugin's binary directory.
public class PluginAssemblyLoadContext: AssemblyLoadContext
{
// Resolver of the locations of the assemblies that are dependencies of the
// main plugin assembly.
public AssemblyDependencyResolver _resolver;
private readonly string _mainAssemblyPath;
public PluginAssemblyLoadContext(string pluginPath) : base(isCollectible: false)
{
_resolver = new AssemblyDependencyResolver(pluginPath);
}
// The Load method override causes all the dependencies present in the plugin's binary directory to get loaded
// into the HostAssemblyLoadContext together with the plugin assembly itself.
// NOTE: The Interface assembly must not be present in the plugin's binary directory, otherwise we would
// end up with the assembly being loaded twice. Once in the default context and once in the HostAssemblyLoadContext.
// The types present on the host and plugin side would then not match even though they would have the same names.
protected override Assembly Load(AssemblyName assemblyName)
{
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
{
var assembly = LoadFromAssemblyPath(assemblyPath);
return assembly;
}
return null;
}
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
string libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
if (libraryPath != null)
{
return LoadUnmanagedDllFromPath(libraryPath);
}
return IntPtr.Zero;
}
}
var webApiAlc = new PluginAssemblyLoadContext(file);
Assembly assembly = webApiAlc.LoadFromAssemblyPath(file);
MethodInfo entryPoint = assembly.EntryPoint;
string[] methodParams = new string[] { path };
var result = entryPoint.Invoke(null, new object[] { methodParams });
Error message
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.MissingMethodException: Method not found: 'Microsoft.Extensions.Hosting.IHostBuilder
Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.ConfigureAppConfiguration(Microsoft.Extensions.Hosting.IHostBuilder, System.Action`1<Microsoft.Extensions.Configuration.IConfigurationBuilder>)'.
- 主要言語
- C#
- スター
- 3.7k
- フォーク
- 5.1k
- 平均マージ
- 19時間 47分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/samples のほかの issue
-
dotnet-target-version
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
dotnet-target-version
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
dotnet-target-version
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Race condition in orleans/ShoppingCart/Grains/InventoryGrain.cs#L48対応中かも @TimonPasslick が 160 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
dotnet-target-version
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
似ている issue
-
Audit by ear: boss warnings, other not-enough messages, ailments and barriers in a chapter 1 battleオープンenhancement needs-game ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Sour-Dev-Home/metaphor-accessibility#1273 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
joinrpg/joinrpg-net#6336 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
muxinc/mux-csharp#88 ·
-
In-car displays show 0 km/h and P while the AV drives対応中かも @bazilinskyy が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
bazilinskyy/coupled-sim#366 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 3 日以内に返信