Welcome to the navigation

Ut incididunt elit, commodo in cillum tempor ad consequat, magna labore exercitation occaecat quis fugiat ex est excepteur proident, aliquip cupidatat nostrud velit qui voluptate. Laborum, in dolore ut quis esse exercitation veniam, id culpa et commodo ut elit, ad sed eiusmod mollit consectetur reprehenderit ex ipsum proident, do laboris

Yeah, this will be replaced... But please enjoy the search!

Episerver: Could not load file or assembly StructureMap.Web

Upgraded some Episerver packages and ended up with bad assembly references. 

The error

Could not load file or assembly 'StructureMap.Web, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
The located assembly's manifest definition does not match the 
assembly reference. (Exception from HRESULT: 0x80131040)

Stack Trace

[FileLoadException: Could not load file or assembly 'StructureMap.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   EPiServer.ServiceLocation.Internal.StructureMapLifecycleTransformer.GetLifeCycle(ServiceInstanceScope scope) +0
   EPiServer.ServiceLocation.Internal.StructureMapConfiguredType`1.LifecycleIs(ServiceInstanceScope lifecycle) +27
...

Solution

So somehow the upgrade linked the wrong nuget package

This can be confirmed by checking the csproj-file

<Reference Include="StructureMap.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
  <HintPath>..\packages\structuremap.web-signed.3.1.6.191\lib\net40\StructureMap.Web.dll</HintPath>
</Reference>

 Solution

Check your packages folder, I'd bet there is another version of StructureMap available, in my case 

<Reference Include="StructureMap.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
  <HintPath>..\packages\structuremap.web.4.0.0.315\lib\net40\StructureMap.Web.dll</HintPath>
</Reference>

Replacing the structuremap.web-signed.3.1.6.191 with the correct version structuremap.web.4.0.0.315.

You may also need to reinstall the package using the nuget console

Update-Package StructureMap.Web -Reinstall

Clean and rebuild!