Compilation Error (Website Not Recognizing .NET 4.5) - compilation

I am trying to get a website to recognize a new version of .Net (4.5) so that I can upgrade to the final version of DNN (7.2). I have .Net 4.5 installed but when I go into the IIS settings, switch the framework to 4.5 (it actually says 4.0 bc the version is technically 4.03), and then refresh local host I get the error:
"Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1703: An assembly with the same identity 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' has already been imported. Try removing one of the duplicate references.
[No relevant source lines]"
Haven't found anything useful thus far on the web regarding this. Please Help!
Update: the version referenced in the web.config does say 3.5.0.0 Is this the issue?

Your website only needs to be configured to use .Net 4.0
.Net 4.5 is an extension of the version 4.0.
Depending on the method you use to switch from .Net 2.0 to .Net 4.0, you would have to replace references to version 3.5 by references to version 4.0 in your web.config.

I was moving a dnn site from SSMS 2008 to 2012 to upgrade a DotNetNuke 4.8.0 site to 5.4.0 (I know it's old and that it's 5.4 and stable, I can continue the upgrade path) and came across the Compiler Error Message.
Compiler Error Message: CS1703: An assembly with the same identity
'System.Web.Extensions, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad36e35' has already been imported. Try
removing one of the duplicated references.
I replaced two references to 3.5 to 4.0 in web.config and it fired right up after I replaced the old core files with the 5.4 upgrade files.

I had a similar build error:
An assembly with the same identity 'System.Runtime, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' has already been
imported. Try removing one of the duplicate references.
The problem was with <assemblyBinding> in web.config. I had to change
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
To (note the binding redirect versions)
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I think the original assembly binding redirect was added when I upgraded the site from asp.net 2.0 to 4.0. For some reason this worked on one of my machines but when I checked out the project on another machine the build failed.

In my case, I've installed something from Nuget (Humanizer) and it created a folder in my web site called packages where it added new references to basically every knwon .net class (it seems that it needed to resolve some dependencies - a lot of dependencies!! :)) ), that is why I had multiple references to a lot of .net classes. I've removed that package entirely and it removed with it all other dependency references.
Now all is ok.. thank God! :)

Related

assemblyBinding understanding Newtonsoft.Json and Common.Logging connection

I added to my project Newtonsoft.Json via Nuget.
After I did that I found VS added these section:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Q1: Why is it doing that? What is the purpose?
Q2: Why does Common.Logging appear there as well? I never added Common.Logging via Nuget.
Q3: Do I need to add Common.Logging via Nuget? I tried, installed Common.Logging via Nuget via Nuget and found out it also installed Common.Logging.Core. But the config section above did'n change!
Can someone explain me in very simple language without copy-pasting from MSDN what this whole circus is for? How does it work, and why Common.Logging suddenly was added to this section, do I actually need to install it along with Common.Logging.Core, when I need only Newtonsoft.Json?
Thanks.
Q1: Why is it doing that? What is the purpose?
Simple language is that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app.config) file.
For example, you have application A that references library B, and also library C with version 1.0.0.0. Library B in turn also references library C, but the version 1.1.0.0. Now we have a conflict, because you cannot load different versions of the same assembly at runtime. To resolve this conflict you might use binding redirect.
If you are interested, you can see Redirecting Assembly Versions for more details
Q2: Why does Common.Logging appear there as well? I never added
Common.Logging via Nuget.
Not sure why it also add Common.Logging. It may be more related to your project. Probable, your project indirectly references this nuget package as reference or your project reference this assembly directly. Because Add-BindingRedirect will examines all assemblies within the output path for a project and adds binding redirects to the application or web configuration file where necessary.
Certify: Add-BindingRedirect
Q3: Do I need to add Common.Logging via Nuget? I tried, installed
Common.Logging via Nuget via Nuget and found out it also installed
Common.Logging.Core. But the config section above did'n change!
If you can make sure you only need Newtonsoft.Json, you do not need to add Common.Logging via Nuget.
Hope this helps.

NuGet adds System.Runtime to web.config on every update causing run-time error

I have a solution with multiple projects, two of them being MVC5 web apps.
Every time I update any nuget package in any project, the mvc apps' web.config is modified, adding the following:
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
</dependentAssembly>
This causes runtime error:
[BadImageFormatException: Could not load file or assembly
'System.Runtime' or one of its dependencies. Reference assemblies
should not be loaded for execution. They can only be loaded in the
Reflection-only loader context. (Exception from HRESULT: 0x80131058)]
If I remove this entry from the web.config, everything works OK, it's just annoying to remember to do it every time.
Any ideea why is this happening?
so this came up for me after I had manually added a link to system.runtime.dll at location
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Runtime.dll
Removing this fixes this problem but the reason I added it in the first place was because I needed a portable nuget package that required that dll to build. So I ended up leaving it in place and manually deleting it all the time. :(

Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API

this problem is exactly the same as this post http://forums.asp.net/t/1807797.aspx/1?System+Net+Http+is+not+found and this one on StackOverflow
I have all the latest RTM bits, Started a new MVC 4 in .Net 4.5, added the WebAPI nuget package and now my code analysis fails with the same error as reported in the above link.
CA0058 Error Running Code Analysis CA0058 : The referenced assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. This assembly is required for analysis and was referenced by: C:\Projects\InHouse\TimeRecorder\StopGap\TimeRec\bin\TimeRec.dll, C:\Projects\InHouse\TimeRecorder\StopGap\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll. [Errors and Warnings] - (Global)
From what I can find this seemed to happen with the RC versions because there was a conflict between the .NET 4.5 framework System.Net.Http and the WebApi's version of the System.Net.Http.
The other answers on the StackOverflow response talk about downgrading from .Net 4.5 to 4.0, for obvious reasons, this is not my preferred solution!
Try the following:
Depending on your Visual Studio edition navigate to:
VS 2010:
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop
VS 2012:
%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop
Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode
from StrongName to StrongNameIgnoringVersion.
Save the change and rebuild your project.
From Visual Studio 2012 and higher, instead of modifying your installation files, use the workaround specified here: Using Microsoft.Bcl.Async with Code Analysis causes errors.
I have had the same problem (couldn't build locally and remotely on azure).
This workaround helped me:
http://connect.microsoft.com/VisualStudio/feedback/details/760208/nuget-package-for-asp-net-mvc-4-web-api-does-not-reference-correct-net-4-5-assemblies#
here is the part you need:
Copy the System.Net.Http.dll and System.Net.Http.xml files contained in the packages\Microsoft.Net.Http.2.0.20710.0\lib\net40 directory to the packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40 directory. Since the missing System.Net.Http.dll assembly is now in the same location as the referenced System.Web.Http.dll assembly, the code analysis can now properly resolve the conflicting System.Net.Http assembly.
The issue is caused because you have a dependency on a newer version of System.Net.Http, than that required by one of the other assemblies referenced.
The correct way to resolve this issue is to add dependentAssembly redirects to the app.config of offending projects. The accepted answer of disabling the errors just masks an underlying problem.
Add the following to the runtime section of app.config to remap the old version that can't be resolved to the version referenced in your project. The version numbers should obviously be updated to correspond to your situation.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Version-specific assembly references when Specific Version is False

I've recently started having problems with my projects wanting specific versions of their referenced assemblies even though the references are marked as Specific Version = False in my Visual Studio project. For example, I'll replace MyAssembly.dll version 1.0.0.0 with MyAssembly 1.0.1.0 and the applications referencing MyAssembly.dll will get an error saying version 1.0.0.0 cannot be found. The specific version property doesn't seem to be working. This is a huge pain because I have to rebuild and redeploy every application that references the assembly even if there are no breaking changes in the new version. I know in the past when this has been false it would use any version and if more than one was found it would use the latest version. Does anyone know what the problem is?
Edit: This has been open with no responses for a while. Is the question unclear? What I want to know is, is there a way to update assemblies my .NET application depends on to a new version without rebuilding my .NET application.
Hi I just had the same problem with a Sharepoint project and I fixed it by editing the app.config file and add the following ind the configuration tag. That did the trick..
The Specific Version is a compile time issue.. I didn't know that.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint.Dsp" publicKeyToken="71e9bce111e9429c" culture="neutral" />
<bindingRedirect oldVersion="11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<runtime>

Type mismatch after installing MVC 3 in a MVC 2 view

HI All,
after installing ASP.NET MVC 3 and opening my current MVC 2 project all seemed to be fine. But when opening a view which uses System.Web.MVC.SelectList I get the following error:
Error 205 Value of type 'System.Web.Mvc.SelectList' cannot be converted to 'System.Web.Mvc.SelectList'. Type mismatch could be due to mixing a file reference to 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll' in project 'DSMStoreFront' with a file reference to 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' in project '2_Views_Basket_Overview.aspx'. If both assemblies are identical, try replacing these references so both references are from the same location.
When debugging the whole project nothing else happens so I just think this is a small issue in the editor of MVC-views. But maybe someone knows a solution to fix it?
All references are targeted at MVC 2 and the two web.configs (root & views-folder) owe the following reference:
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Many thanks in advance!
If you've installed MVC3 are you looking to use it for this project or did you want to stick with MVC2 for now? Are you using IIS6 by chance with any script maps? Also I remember that MVC3 is for .NET 4.0 exclusively, is your app using.NET 4.0 or 3.5? I've not had the problem you're running into specifically so I'm just throwing out some ideas. Maybe try doing a quick search of your project contents or the project file itself for any references that point to 3, that shouldn't be if you're trying to stick with MVC2.
If you're wanting to upgrade to 3.0 you'll have to add the following to your web.config.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Alternatively, I wonder if you can modify that assembly mapping to redirect requests for 3.0 to map back to 2.0?

Resources