为什么在IIS发布上发生程序集加载错误

问题描述 投票:1回答:1

我创建了一个扩展方法来在我的asp.net核心Web API项目中找到我的界面实现。

    public static List<Type> FromAssembliesMatching<TType>(this AppDomain currentDomain, string searchPattern)
    {
        var referencedPaths = Directory.GetFiles(currentDomain.BaseDirectory, "*.dll").ToList();

        var assemblies = referencedPaths.Select(path => currentDomain.Load(AssemblyName.GetAssemblyName(path)));

        var types = assemblies.SelectMany(s => s.GetTypes().Where(t =>
                typeof(TType).IsAssignableFrom(t)
                && !t.IsInterface
                && !t.IsAbstract))
            .ToList();

        return types;
    }

例如,找到IMyInterface实现的类型。这在开发应用程序时有效。

但是当我在iis上发布它时。

System.BadImageFormatException: Could not load file or assembly 'C:\publish\api-ms-win-core-console-l1-1-0.dll'.

扩展方法试图加载所有dll。我认为C#生成的dll会导致错误。我该如何解决这个问题?

c# .net asp.net-core system.reflection
1个回答
0
投票

这是预期的。

© www.soinside.com 2019 - 2024. All rights reserved.