Could not load file or assembly Microsoft.Practices.ServiceLocation, Version=1.3.0.0

11

Here is the error I'm getting when I run my application (.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

I installed the nuget package CommonServiceLocator, but I'm still getting this error. The weird thing is that there is an assembly binding redirect in my web.config file, but the assembly does not appear in the reference list for my project and I cannot find it anywhere to add it. I'm still relatively new to ASP.NET, so I can't seem to pin down what the issue is exactly. Another thing I found to try is to set 'Enable 32 bit applications' to true for my application pool in the IIS Manager, but this did not fix my problem. I've been stuck on this for a while, so any help would be appreciated.

c#
asp.net
.net
visual-studio-2015
nuget
asked on Stack Overflow Feb 16, 2016 by Otto45

6 Answers

13

Well after hours of research and trying different things, uninstalling and reinstalling CommonServiceLocator from Nuget seemed to do the trick. I'm still amazed at how messy .NET apps are with their dependencies.

answered on Stack Overflow Feb 16, 2016 by Otto45
6

Make sure you have installed version 1.3.0 and not a different version.

Nuget link: https://www.nuget.org/packages/CommonServiceLocator/1.3.0

answered on Stack Overflow Jan 24, 2018 by Ted Mosby • edited Jan 24, 2018 by Taegost
0

Open VS--> Tools --> Nuget Package manager--> Package manager Console

>PM Install-Package CommonServiceLocator

This should help!

answered on Stack Overflow Sep 5, 2016 by Kamlendra Sharma • edited Nov 30, 2016 by sparkyShorts
0

I was getting this error because I was using the new syntax of C# 7.0 in an older version. Once I reverted back to the older syntax, this was resolved.

Specifically, I was using:-

// 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;
}
answered on Stack Overflow Sep 2, 2017 by footyapps27
0

I had opened a VS2015 Solution in VS2017 and found missing references, not sure why.

  • Could not locate the assembly "CommonServiceLocator"
  • Could not locate the assembly "Unity.RegistrationByConvention"
  • Could not locate the assembly "Unity.ServiceLocation"
  • Could not locate the assembly "Unity.Configuration"
  • Could not locate the assembly "Unity.Interception.Configuration"
  • Could not locate the assembly "Unity.Container"

Build your project first to get a list of missing references (that show the release numbers). Then open the NUGET package manager for the solution and simply reinstall. Note: there are dependency chains to the install order, if an install fails, find the pre-req. dependency and install first, then try again. Takes about 10 minutes to correct.

answered on Stack Overflow Oct 3, 2018 by JWP
0

They have updated the package, below change is required in code if you download the latest commonservicelocator package.

using Microsoft.Practices.ServiceLocation;

to

using CommonServiceLocator;
answered on Stack Overflow Mar 7, 2020 by Unnie

User contributions licensed under CC BY-SA 3.0