I have a Visual Studio solution with an asp.net web application project and a class library project alongside it.
The applications runs fine when I debug it in Visual Studio, however when I deploy it using WebDeploy, I get the following exception when loading the page:
System.IO.FileLoadException:
Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.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)
This also happens when deploying to a Folder.
My web project references Microsoft.CodeAnalysis.CSharp version 3.0.0, installed via Nuget and I can see it in the packages folder. Web.config contains this:
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Super confused- I don't see any 1.0.0.0 references anywhere and I don't know how I'm supposed to resolve this. I even tried manually installing version 1.0.0.0 of Microsoft.CodeAnalysis.CSharp alongside the current version and nothing changes.
EDIT:
Okay so this appears to be resolved by turning the "Precompile during publish" option off when deploying. Hesitant to answer my own post with this because I suspect this is not a real solution.
In case you are using an older version of Microsoft.CodeDom.Providers.DotNetCompilerPlatform
nuget, you can update that and try deploying again.
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
also references Microsoft.CodeAnalysis.CSharp
There are a few different causes that have this sort out output, one of the main ones is when the main project, in your case the web application, does not have a specific reference to the dlls in question, and you are assuming that the build and deployment pipeline will correctly pickup all the dlls from the output of any dependant projects directly into the deployment package.
When nuget references are used in the satellite assemblies they are not automatically copied across. The main project needs specific pointers in the deployment scripts to know where to source the correct dlls from.
You may experience this issue on some dev boxes and not others for the same solution, or when you compare the dll outputs from both the satellite project and the web project that you are deploying you see that the web project has different versions of the dependant dlls
Make sure that you install ALL nuget packages that are installed in your satellite projects into the main web project.
Make sure that the same versions of packages in the satellite projects are installed in the main project.
If all of the above is correct, then you should look at the binding redirects in the web.config. This can be involved, instead start first with reinstalling all the nuget packages.
This can work because the installation scripts for nuget packages will automatically set binding redirects that may be necessary for your combination of dependancies
Remove the assemblyBinding
node from web.config if it is already there. Start fresh.
npm: (where MyProject
is the name of your web project)
update-Package -ProjectName MyProject -reinstall
That should do the trick!
ASP.NET web projects and other projects that have in-built deployment pipelines exhibit these issues more than other project types. Only the compiled dlls from the dependant projects are copied directly into the output of the deployment project, any nuget references for additional dependencies are expected to be resolved in the deployment project, otherwise if there are similar named assemblies in the GAC they will be used instead.
Using Strongly Named references can assist in avoiding these issues but that is usually a lot harder solution to implement if you use a lot of 3rd party assemblies that are not strongly named.
This was an ironic experience for me as the cause and solution are similar to my very first post on SO: Azure package not including linked project DLL even with copy local set its a slightly different flavour but I should have known better by now!
User contributions licensed under CC BY-SA 3.0