无法加载文件或程序在Visual Studio 2012,C# [英] Could not load file or assembly in Visual Studio 2012, C#

查看:514
本文介绍了无法加载文件或程序在Visual Studio 2012,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7上工作的一个C#代码上的Visual Studio 2012我的解决方案包含多个项目。

I’m working on a C# code on Visual Studio 2012 on Windows 7. My solution contains several projects.

最近,我在我的解决方案增加了一个新的项目,并加入这个新项目的DLL中的其他2个项目在该溶液中引用(是的启动项目之一)。新项目本身引用到不包括在我的解决方案的其他几个项目。

I recently added a new project in my solution, and added the dll of this new project in the references of 2 other projects in the solution (one of the being the startup project). The new project itself is referencing to several other projects that are not included in my solution.

在解决建设项目工作正常,但是当我尝试运行该程序(在调试或发布)我得到一个错误。以下是错误:

Building the projects in the solution works fine, but when I try to run the program (in Debug or in Release) I get an error. Here is the error:

System.IO.FileNotFoundException was caught
  HResult=-2147024894
  Message=Could not load file or assembly 'ABCD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
  Source=NP
  FileName=ABCD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog==== Pre-bind state information ===
LOG: User = MyCompany\MyName
LOG: DisplayName = ABCD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : NP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\MyName\Documents\Visual Studio 2012\Projects\MyProgram\Analysis\bin\Debug\Analysis.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/ABCD.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/ABCD/ABCD.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/ABCD.EXE.
LOG: Attempting download of new URL file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/ABCD/ABCD.EXE.

  StackTrace:
       at NewProject.DATA.SetType(NP np, String code, OrderType orderT, MODEL MODELv)
       at NewProject.DATA.SetData(NP np, String no, String type, String law, String time, OrderType orderT, MODEL MODELv)
  InnerException:

分析是我的启动项目。
NewProject是我最近添加到我的解决方案项目。
ABCD.dll在NewProject引用,但该项目ABCD是不是解决方案的一部分。

Analysis is my startup project. NewProject is the project I added recently to my solution. ABCD.dll is referenced in NewProject, but the project ABCD is not part of the solution itself.

在此错误,它是说,是应用平台文件:/// C:/用户/ MYNAME /文件/的Visual Studio 2012 /项目/ MyProgram /分析/斌/调试/

In this error, it is said that the AppBase is file:///C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/

然而,当我看在NewProject ABCD参考,它说:

However, when I look at the ABCD reference in NewProject, it says:

Assembly ABCD
    C:\Users\MyName\Documents\Visual Studio 2012\Projects\np\bin\ABCD.dll

事实上,ABCD为.dll在不写入错误的应用平台地址。但我从来没有说,这是在那里,我不明白的地方这从何而来。

Indeed, ABCD.dll in not in the AppBase address written in the error. But I never said it was there, and I don’t understand where this comes from.

我试图把ABCD.dll的应用平台解决错误是给我。但每次我重建NewProject和(当时)我的启动项目分析,ABCD.dll从C消失:/用户/ MYNAME /文件/的Visual Studio 2012 /项目/ MyProgram /分析/斌/调试/

I tried to put ABCD.dll in the AppBase address the error is giving me. But each time I rebuild NewProject and (then) my startup project Analysis, ABCD.dll disappears from C:/Users/MyName/Documents/Visual Studio 2012/Projects/MyProgram/Analysis/bin/Debug/

我很新的Visual Studio中。我可能做错了什么事我添加新项目时,但我不明白它是什么。如果你一个人有关的方法来解决这个问题的想法,请不要犹豫,说话!

I am quite new to Visual Studio. I probably did something wrong when adding my new project but I can’t understand what it is. If one of you has an idea regarding the method to solve this issue, please don’t hesitate to speak !

推荐答案

如果您需要项目之间的引用,然后添加项目引用,而不是引用的DLL文件。如果你真的需要引用一个DLL文件,然后:

If you need references between projects, then add "Project references" instead of referencing DLL files. If you really need to reference a DLL file, then:

1)创建一个库(或其它)文件夹中的项目

1) Create a "Libraries" (or something) folder in your project.

2)引用的DLL复制到这个文件夹。

2) Copy the referenced DLL into this folder.

3)在VS中,使用添加现有项目将DLL文件添加到该项目。在选择对话框中的文件,你需要将文件过滤器改为 *。* 为DLL出现。

3) In VS, use "Add existing item" to add the DLL file to the project. In the file choosing dialog box you need to change the file filter to *.* for the DLL to appear.

4)在此DLL的节点的属性选择构建选项如果新版本了。

4) Under the properties of this DLL's node choose "Copy if newer" in Build option.

5)的DLL文件添加的库目录参考。

5) Add reference to the DLL file in the "Libraries" directory.

引用是当然更好,因为作为重建它们的引用会自动更新。否则,你必须要更新的基准每次用新的来替换DLL文件。

References between projects are of course better, because as your rebuild them your references are updated automatically. Otherwise you need to replace the DLL file with a fresh one each time you want to update the reference.

这篇关于无法加载文件或程序在Visual Studio 2012,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆