[英]Could not load file or assembly when starting complex ASP.NET Core application
I have complex ASP.NET Core solution, which consists of:我有复杂的 ASP.NET Core 解决方案,其中包括:
I want to add extension method to this class libraries, so they could register themselves, eg:我想向此类库添加扩展方法,以便他们可以自行注册,例如:
public static IServiceCollection AddThisLibrary(this IServiceCollection services)
{
//a lot of addTransient...
return services;
}
which I use in Startup
class in ConfigureServices
method, like this:我在ConfigureServices
方法的Startup
类中使用它,如下所示:
services.AddThisLibrary();
The problem is, that when I'm starting my application, it throws the exception:问题是,当我启动我的应用程序时,它抛出异常:
An error occurred while starting the application.启动应用程序时发生错误。 FileNotFoundException: Could not load file or assembly 'MyProject.API.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. FileNotFoundException:无法加载文件或程序集“MyProject.API.Service,版本=1.0.0.0,文化=中性,PublicKeyToken=null”。 The system cannot find the file specified.系统找不到指定的文件。 MyProject.API.Web.Startup.ConfigureServices(IServiceCollection services) MyProject.API.Web.Startup.ConfigureServices(IServiceCollection 服务)
for each my library.对于我的每个图书馆。
I've checked /bin/Debug folder, where I have all my class libraries built in DLL , so I have no idea, why they can't be found.我检查了/bin/Debug文件夹,在那里我的所有类库都内置在DLL 中,所以我不知道为什么找不到它们。
How can I properly write such extension methods and remove that exception?如何正确编写此类扩展方法并删除该异常?
you should check that your dll is the same version as the one it is trying to load it, what i suggest is go to your reference, remove the existing one, go to your assembly remove it as well, then clean, then add it to your references again, build.您应该检查您的 dll 是否与它尝试加载的版本相同,我建议去您的参考资料,删除现有的,去您的程序集删除它,然后清理,然后将其添加到再次参考,构建。 Make sure you have one reference only.确保你只有一个参考。
My case may be specific a lot, but I faced this error when changed target from .net core 3.1 to .net 5. Some files in deploy folder remained from prevous deploys.我的情况可能很具体,但是当将目标从 .net core 3.1 更改为 .net 5 时,我遇到了这个错误。 deploy 文件夹中的一些文件仍然来自以前的部署。 I clean the folder an published once again.我再次清理发布的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.