简体   繁体   English

Visual Studio 2019 错误 - 无法加载文件或程序集或其依赖项之一

[英]Visual Studio 2019 Error - Could not load file or assembly or one of its dependencies

I have some trouble with running my project.我在运行我的项目时遇到了一些问题。 When I try to run, the following error appears:当我尝试运行时,出现以下错误:

FileNotFoundException: Could not load file or assembly 'Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. FileNotFoundException:无法加载文件或程序集“Dapper,Version=2.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。 The system cannot find the file specified该系统找不到指定的文件

Context:语境:

I have a Class Library X and a Web Application Y which have dependencies on X. When I try to run my API project, it throws the above error.我有一个 Class 库 X 和一个 Web 应用程序 Y,它们依赖于 X。当我尝试运行我的 API 项目时,它会抛出上述错误。 BUT, when my colleagues try to run the same API project, it works fine (no errors, and in /bin folder, it loads all the.dll libraries..)但是,当我的同事尝试运行同一个 API 项目时,它工作正常(没有错误,并且在 /bin 文件夹中,它加载了所有 .dll 库..)

I did those approaches:我做了那些方法:

  • Restart Visual Studio, clean and build a solution重新启动 Visual Studio,清理并构建解决方案
  • Remove the class library references and add it again删除 class 库引用并重新添加
  • Tools > Import and Export Settings Wizard > Reset all settings (maybe some setting was not well configured).工具 > 导入和导出设置向导 > 重置所有设置(可能某些设置配置不当)。 I also tried to import colleague settings and didn't work either.我也尝试导入同事设置,但也没有用。

I tried various approaches(even in a different machine, but same VS settings) but none of these worked for me.我尝试了各种方法(即使在不同的机器上,但 VS 设置相同)但这些方法都不适合我。

Visual studio 2019 16.4 Enterprise. Visual Studio 2019 16.4 企业版。

I'd also try:我也会尝试:

1) Deleting your bin and obj folders in your solution before a rebuild. 1) 在重建之前删除解决方案中的 bin 和 obj 文件夹。

2) Check that you've not got multiple versions of the same package across the solution (right click on solution in solution explorer -> manage nuget packages for solution). 2) 检查您在解决方案中是否没有同一包的多个版本(右键单击解决方案资源管理器中的解决方案 -> 管理解决方案的 nuget 包)。

3) Check that the properties of the reference (right click in solution explorer on the reference in question) shows a path to the package that you'd expect relative to the solution (eg not in mydocuments/nuget packages or something!). 3) 检查参考的属性(在有问题的参考的解决方案资源管理器中右键单击)显示您期望相对于解决方案的包的路径(例如不在 mydocuments/nuget 包或其他东西中!)。

4) Try a fresh clone of the repo (this should in effect replicate your co-workers' set up) and see if the problem still exists then. 4) 尝试一个新的 repo 克隆(这实际上应该复制你同事的设置),然后看看问题是否仍然存在。

I suppose another cause could be that your coworkers have a locally installed package / dll that they're happily referencing without realising, but you don't have?我想另一个原因可能是你的同事有一个本地安装的包/dll,他们很乐意在没有意识到的情况下引用,但你没有?

When you copy a project from someone or another system, you need to download and install all components.当您从某人或其他系统复制项目时,您需要下载并安装所有组件。 normally VS will give you the option to "restore packages" when you load a newly imported from git but not sure if it does when you open an existing solution from a different system.通常 VS 会在您加载从 git 新导入的文件时为您提供“恢复包”的选项,但不确定当您从不同系统打开现有解决方案时是否会这样做。

Right Click your project, Manage Nuget Packages右键单击您的项目,管理 Nuget 包
Browse -> Search for Dapper.浏览 -> 搜索 Dapper。 Install安装

In the error you receieve, it tells you what version of the package should be installed as well.在您收到的错误中,它还告诉您应该安装哪个版本的软件包。 Installing a significantly different version might cause other unexpected errors.安装明显不同的版本可能会导致其他意外错误。

thank you for your solutions but I found the problem:感谢您的解决方案,但我发现了问题:

The project solution has some projects with .net standard 2.0 and some with .net framework 4.8.项目解决方案有一些项目使用 .net standard 2.0,一些项目使用 .net framework 4.8。 Somehow, when I run the app, some packages are not loaded correctly and it throws an error.不知何故,当我运行该应用程序时,某些包未正确加载并引发错误。

That line below solved my problem:下面那一行解决了我的问题:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

Put it in all .net framework 4.8 projects on first XML tag.将它放在所有 .net framework 4.8 项目中的第一个 XML 标记上。

Thank your for all.谢谢你的一切。

Regards.问候。

I had exactly the same Dapper error message today when referencing a.Net Standard 2.1 class library in a.Net Core 3.1 WinForm app.今天在 .Net Core 3.1 WinForm 应用程序中引用 .Net Standard 2.1 class 库时,我收到了完全相同的 Dapper 错误消息。 My resolution was to double-click the class library name in Solution Explorer to open the.csproj file, and then add a CopyLocalLockFileAssemblies tag to the PropertyGroup tag and setting it to true.我的解决方案是在Solution Explorer中双击class库名打开.csproj文件,然后在PropertyGroup标签中添加CopyLocalLockFileAssemblies标签并设置为true。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual C#“无法加载文件或程序集或其依赖项之一” - Visual C# “Could not load file or assembly or one of its dependencies” 错误0004:无法加载文件或程序集或其依赖项之一 - error 0004: Could not load file or assembly or one of its dependencies 错误原因:无法加载文件或程序集”或其依赖项之一 - What cause to error: Could not load file or assembly '' or one of its dependencies 无法加载文件或程序集或其依赖项之一,错误消息已更改 - Could not load file or assembly or one of its dependencies, error message changing 错误无法加载文件或程序集“AjaxControlToolkit”或其依赖项之一 - ERROR Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies 无法加载文件或程序集或其依赖项之一 - Could not load file or assembly or one of its dependencies 无法加载文件或程序集或其依赖项之一 - could not load file or assembly or one of its dependencies 无法加载文件或程序集或其依赖项之一 - Could not load file or assembly or one of its dependencies 无法加载文件或程序集&#39;&#39;或其依赖项之一 - Could not load file or assembly '' or one of its dependencies 无法加载文件或程序集及其依赖项之一 - Could not load file or assembly and one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM