I have a webproject I am trying to host, but when the server tries to compile it, I get the following error:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=220.127.116.11, 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) ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=18.104.22.168, 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)
--- End of inner exception stack trace --- at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String args)
So the server has an older version of CodeAnalysis than my project. So lets try a binding redirect!
<dependentAssembly> <assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-22.214.171.124" newVersion="126.96.36.199" /> </dependentAssembly>
Sadly, I still get the same error. What am I doing wrong?
I figured this out myself. To anyone reading this, the problem was that the Nuget package
Microsoft.CodeDom.Providers.DotNetCompilerPlatform (which also contains the CodeAnalysis package) was the wrong version. I created a new webproject, updated the offending Nuget package right away, and the problem was solved.
I resolved this issue but ensuring that the version numbers of the assemblies in my web.config were correct.
Changing the version number in Web.Configs compiler (in the Web.Template.Config) to the number matches the NuGet version does solve the issue:
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=188.8.131.52
Other possible fix (at least for Visual Studio 2015):
Get the latest Visual Studio update.
You can check for updates by going to
Tools/Extensions and Updates/Updates
I have had this problem today while doing an Umbraco v7.13.0 upgrade, simply updating the following package has fixed my problem, this is apparently a common problem with things like Umbraco upgrades.
Update-Package -Reinstall Microsoft.CodeAnalysis.CSharp
If none of mentioned options work, please go for this answer. Basically, you are registering that Microsoft.CodeAnalysis.dll to GAC
User contributions licensed under CC BY-SA 3.0