无法加载文件或程序集Microsoft.Practices.ServiceLocation,Version = 1.3.0.0

时间:2016-02-16 14:56:49

标签: c# asp.net .net visual-studio-2015 nuget

这是我运行应用程序时遇到的错误(.NET 4.5):

Server Error in '/' Application.

Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Austin/Documents/FileStore/FileStore.Web/
LOG: Initial PrivatePath = C:\Users\Austin\Documents\FileStore\FileStore.Web\bin
Calling assembly : Chicago.Security, Version=1.0.5826.21195, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Austin\Documents\FileStore\FileStore.Web\web.config
LOG: Using host configuration file: C:\Users\Austin\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 1.3.0.0 redirected to 1.3.0.0.
LOG: Post-policy reference: Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Chicago.Security.AuthenticationModule.application_AuthenticateRequest(Object sender, EventArgs e) +0
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

我安装了nuget包CommonServiceLocator,但我仍然收到此错误。奇怪的是我的web.config文件中有一个程序集绑定重定向,但程序集没有出现在我的项目的引用列表中,我无法在任何地方找到它来添加它。我还是相对较新的ASP.NET,所以我似乎无法确定问题究竟是什么。我发现尝试的另一件事是在IIS管理器中为我的应用程序池设置“启用32位应用程序”为true,但这并没有解决我的问题。我已经坚持了一段时间,所以任何帮助都会受到赞赏。

6 个答案:

答案 0 :(得分:12)

经过数小时的研究和尝试不同的事情,从Nuget卸载并重新安装CommonServiceLocator似乎可以解决问题。我仍然对.NET应用程序与其依赖项的混乱程度感到惊讶。

答案 1 :(得分:3)

确保您已安装版本1.3.0而不是其他版本。

Nuget链接:https://www.nuget.org/packages/CommonServiceLocator/1.3.0

答案 2 :(得分:0)

打开VS - >工具 - > Nuget包管理器 - >包管理器控制台

>PM Install-Package CommonServiceLocator

这应该有帮助!

答案 3 :(得分:0)

我收到此错误是因为我在旧版本中使用了C#7.0的新语法。一旦我恢复到旧的语法,这就解决了。

具体来说,我正在使用: -

// Newer syntax.
if (int.TryParse(args.Value, out var value))
{
  args.IsValid = value > 0;
}

// Older supported version which resolved the issue.
int value;
if (int.TryParse(args.Value, out value))
{
  args.IsValid = value > 0;
}

答案 4 :(得分:0)

我在VS2017中打开了VS2015解决方案,发现缺少参考,不确定原因。

  • 无法找到程序集“ CommonServiceLocator”
  • 无法找到程序集“ Unity.RegistrationByConvention”
  • 无法找到程序集“ Unity.ServiceLocation”
  • 无法找到程序集“ Unity.Configuration”
  • 无法找到程序集“ Unity.Interception.Configuration”
  • 无法找到程序集“ Unity.Container”

首先构建您的项目,以获取缺少的引用列表(显示发行版编号)。然后打开该解决方案的NUGET软件包管理器,然后重新安装即可。注意:安装顺序有依赖关系链,如果安装失败,请找到先决条件。依赖性,然后先安装,然后重试。大约需要10分钟才能更正。

答案 5 :(得分:0)

他们已经更新了软件包,如果您下载最新的commonservicelocator软件包,则需要在代码中进行以下更改。

using Microsoft.Practices.ServiceLocation;

using CommonServiceLocator;