System.MissingMethodException: Method not found: 'Microsoft.Extensions.Hosting.IHostBuilder Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.ConfigureAppConfiguration

Đang mở
#7,071 161 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với phần triển khai PluginAssemblyLoadContext và lời gọi entry-point dựa trên reflection được thể hiện trong issue. Kiểm tra cách thư mục dependency của plugin và context mặc định resolve các assembly Microsoft.Extensions.Hosting, sau đó tái hiện đường dẫn khởi động. Được xem là hoàn tất khi plugin khởi động thông qua reflection mà không gặp MissingMethodException đã báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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>)'.
Ngôn ngữ chính
C#
Star
3.7k
Fork
5.1k
Merge trung bình
19 giờ 47 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/samples

Tất cả issue của dotnet/samples

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.