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

11

当我运行我的应用程序(.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
我已安装CommonServiceLocator NuGet包,但仍然遇到错误。奇怪的是,我的web.config文件中有一个程序集绑定重定向,但该程序集在我的项目引用列表中未出现,我也找不到它以添加它。我对ASP.NET还比较陌生,所以无法确定问题的确切原因。另一件我尝试的事情是在IIS Manager中将“启用32位应用程序”设置为真,但这并没有解决我的问题。我困扰了很长时间,所以任何帮助都将不胜感激。

你能否尝试从 https://servicelocation.codeplex.com/ 下载 dll 并在删除当前引用后将其添加到项目引用中? - Eray Balkanli
该网站拥有的最新版本是1.2.0.0,而我需要的是1.3.0.0版本。网站上是否存在某种不一致,因为它似乎没有最新版本? - Otto45
6个回答

14

经过数小时的研究和尝试不同的方法,从Nuget卸载并重新安装CommonServiceLocator似乎解决了问题。我仍然惊讶于.NET应用程序与它们的依赖关系有多么混乱。


这对我解决了问题。这已经是第二次在项目的“packages.config”文件中出现了一个未真正安装在项目中的包条目。(即在项目引用中,相应包的dll引用丢失了) - Martin
我也遇到了同样的问题。重新安装CommonServiceLcoation的NugetPackages以及所有依赖它的包对我有用。 - HiTech

6

这对我有用。我的网站引用了1.0.0版本,所以我删除了dll并使用包管理器安装了1.3.0版本,如建议的那样,不再出现错误。 - Jamie Butterworth
如果您查看NuGet上软件包的版本,您会发现从1.4.0开始,程序集具有不同的文件名。因此,对于这个特定的异常,错误可能是使用的软件包版本高于1.3.0。 - rominator007

0

我在VS2017中打开了一个VS2015的解决方案,发现缺失引用,不确定原因。

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

先构建项目以获取缺失引用列表(显示版本号)。然后打开该解决方案的NUGET包管理器并重新安装。注意:安装顺序存在依赖关系,如果安装失败,请查找前置依赖项并先安装,然后重试。需要大约10分钟来修复。


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;
}

0

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

>PM Install-Package CommonServiceLocator

这应该会有所帮助!


0

他们已经更新了这个包,如果你下载最新的commonservicelocator包,那么代码需要做以下更改。

using Microsoft.Practices.ServiceLocation;

using CommonServiceLocator;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接