FSharp.Core: Could not load file or assembly - f#

I have the following error when attempting to run a test:
{System.IO.FileLoadException: Could not load file or assembly
'FSharp.Core, Version=3.3.1.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040) File name:
'FSharp.Core, Version=3.3.1.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' at
Register.RegisterResponse.__DebugDisplay()
Tests.dll
FSharp.Core: 3.1.2.5
Target F# runtime: 4.3.1.0
Target Framework: 4.6
Output type: Class Library
ManageAccount.dll
FSharp.Core: 3.1.2.5
Target F# runtime: 3.3.1.0
Target Framework: .NET Portable Subset (.Net Framework 4.5, ASP.Net Core 1.0, Windows 8)
Output type: Class Library
I then added the following app config to my test project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral"/>
<bindingRedirect oldVersion="3.1.2.5" newVersion="3.3.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
If I do need an app config, what value should my bindingRedirect be set to?

Try <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="3.3.1.0" />. That's what most F# projects seem to be doing for FSharp.Core. (Or newVersion="4.3.1.0", or even newVersion="4.4.0.0" if you upgrade to a newer FSharp.Core).

You should use the newest version (4.3.1.0 in this case) in bindingRedirect/newVersion, otherwise, you will probably get errors from code in Tests.dll assembly which relies on the newer version.
Alternatively you can update the reference in one of the assemblies (downgrade Tests.dll or upgrade ManageAccount.dll) so that they both use the same version.

Related

Could not load file or assembly System.Runtime.CompilerServices.Unsafe on a clean autofac.mv5 installation

I just installed autofac.Mvc5 6.0 on my .net framework 4.7.2 installation.
And without adding any code other than adding the nuget package I get this error:
Could not load file or assembly
System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of it's
dependences. The found Assembly's manifest definition does not match
the Assembly reference. (Exception from HRESULT: 0x80131040)
Anyone got any idea?
You probably have another library that uses a different version of System.Runtime.CompilerServices.Unsafe. What's in web.config?
Did you tried bindingRedirect?
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
If you have a newer version replace it in the newVersion above.

FsUnit: Unable to test portable library due to it and test project having different F#.Core versions

I have a Portable Library, for which the FSharp.Core version is 3.7.4.0. Installing (in the Unit Test project) FsUnit installs, as a dependency, FSharp.Core version 3.1.2.5.
Due to this, using the portable library's functions in my Unit Test project, for example:
module StammaTests.PieceTests
open Stamma
open NUnit.Framework
open FsUnitTyped
[<Test>]
let ``Testing a Basic function`` () =
Piece.toChar Black King |> shouldEqual 'k'
yields error:
Result Message: System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=3.7.4.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
Tried updating the FSharp.Core version from NuGet to 4.0.0.1 (even checking both projects when updating) and now even something simple like :
[<Test>]
let ``Testing the test`` () = 1 |> shouldEqual 1
doesn't work, giving this similar error.
Result Message: System.IO.FileLoadException : Could not load file or
assembly 'FSharp.Core, Version=4.3.1.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
And the error for the first failing test doesn't change.
I feel like I am missing something painfully obvious, and I found several people with similar problems, but I don't understand what they did to solve it (they all seem to have solved it ..) For example this one.
Edit
Both projects are libraries and I do not have an app.config file to add anything to.
Add a binding redirect in your app.config file to redirect all FSharp.Core bindings to your desired version. For example, to use version 4.4.0, your app.config file would look something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I found a solution that actually worked here
Basically, adding an App.config to the test project, and writing the following:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
It adds binding to both Fsharp.Core and NUnit.Framework, unlike the usual solutions where you only add a binding for Fsharp.Core.

Window Update Broke MVC Application

I ran Windows Update yesterday and its introduced some problems when I'm trying to release a new version of my ASP.NET MVC 4 project.
The application compiles and runs okay locally, however when I push the version up to a test-site on my webserver it fell over with the error message:
System.Web.HttpCompileException: (0): error CS1705: Assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
After some research I found that this is due to an update from 4.0.0.0 to 4.0.0.1. I removed the System.Web.Mvc dll from my project and readded the dll that has the later version. Again everything works locally but not on the web. I then went through the web.config's and changed any mention of 4.0.0.0 to 4.0.0.1. Likewise this continues to work internally but fails externally. The error message is:
Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I believe this has something to do with Elmah that I'm using for the error handling.
I tried to reinstall from Nuget as suggested here: Windows update caused MVC3 and MVC4 stop working but that hasn't worked and I'm getting the same error.
Added info:
The server hasn't yet been updated, I'm concerned that updating this might break the existing live version.
The error message is telling me that you have specified an incorrect version number for the MVC assembly in one of your config files. Find it the config file with the incorrect version and change it to match whatever version you are using (you mentioned 4.0.0.1 above). You need to check all the config files including
The one in the project root
The one in the Views folder
You could also do an assembly redirect in your config file to take care of this as well -- If its failing due to a third party lib this might be the most appropriate action to take.
Based on your feedback id suggest using a binding redirect. Add this to your main web.config..
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I had a similar problem where a MS update changed MVC.dll from 3.0.0.0 to 3.0.0.1. I need to maintain various versions of my software so to ensure compatibility I had to copy the 3.0.0.0 dll to my project and reference it there before building the project.
After digging down some more, I found the web.config inside the view folder is pointing to different version System.web.mvc . Once I changed to
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
from
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
change version of System.Web.MVC to 4.0.0.0 from 4.0.0.1
I was able to solve the issue.

Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

I have an MVC5 Web api project. I am getting following error after deployment,
Could not load file or assembly 'WebGrease, Version=1.5.1.25624,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified.The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040) File name: 'WebGrease,
Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
In My project I have following references,
System.Web.Mvc - 5.1.0.0
System.Web.Razor - 3.0.0.0
WebGrease - 1.6.5135.21930
Also I have included Following section in my Web.config file,
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
I have tried with following steps but still not working ,
Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease
I have referred many links on technical blogs but still getting the same error after deployment.
Can any one help me to find the solution?
Thanks
In my case the reason was in folders/configs hierarchy in an application. Try to check that binding redirect is in your root web config.
As an example:
/AppRoot
Web.config1
/Areas/SomeArea
Web.config2
Make sure that you have correct binding redirect in Web.config1.
Hope this helps.

how to use DotNetOpenAuth.Core, Version=4.3.0.0 with vs 2012

i'm using visual studio (2012 or 2013) with asp mvc 4
and it gives me the following error :
Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
i need to use version 4.3.0.0 i installed it using nuget
I know I had problems with the System.Mvc dependency being of the wrong version. Adding the following assembly "rebinding" to your web.config solved the problem (note the version numbers):
<configuration>
<runtime>
<!-- When targeting ASP.NET MVC 3-4, this assemblyBinding makes MVC 1 and 2 references relink
to MVC 3-4 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it. -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Sidenote: I discovered DotNetOpenAuth.Ultimate that bundles everything into one single DLL! It's much much simpler to maintain that the default DotNetOpenAuth and its huge number of packages....

Resources