Type mismatch after installing MVC 3 in a MVC 2 view - visual-studio-2010

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?

Related

Compilation Error (Website Not Recognizing .NET 4.5)

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! :)

asp.net MVC 3 solution doesnt work after opening in VS 12

I created an asp.net MVc 3 application using Visual studio 2010. It was working fine. I uploaded to hosting which has asp.net MVc 3 installed and it worked. I opened this MVC 3 solution in visual studio 2012. At that time, It did some up gradation. It created
151Marketing.v11.suo
UpgradeLog.html
UpgradeLog.xml
and a folder named _UpgradeReport_Files and backup folder.
When I publish this on live server, I get errors of framework. I see a backup folder as wel as I guess it was created before conversion by VS 12. Should I use that or is there any other way to change the current version of code to work on hosting because after i opened it in VS 12, I made several changes as well.
Please suggest
Probably your MVC3 project got updated to MVC4.
Replace the Project type GUID with the old mvc3 ones (in your .csproj file):
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
If that's the case, be careful with the used referenced libraries (version).
If you use MVC4, you should localcopy the assemblies into the /bin directory.
Also, it might have switched to the 4.5 Framework.
You might want to take that down to 4.0. MVC4 also works fine with framework 4.0 by the way.
If that doesn't work, you'll probably better create a new MVC3 project, and copy all the cshtml and Controllers over (not the web.config) from the old project.
If you have administrative rights, you can also install the asp.net mvc4 update for Visual Studio 2010.
If you don't want to localcopy the MVC4 assemblies, you might want to install the MVC4 runtime on the server.
Look at your web.config and see if the references for MVC got upgraded to MVC4. If so, revert those back to MVC3 references.
Seems like a good way I found to deal with upgrades is to backup in a folder the solution and projects etc... and then when you are upgrading /opening/converting to using vs 2012, you can can use "Beyond Compare" or WinMerge" or another comparison tool and see what files got changed.
If any files got changed it will be .sln / .csproj / web.config etc...
I had problem with going from MVC 3 to MVC 4 beta and I posted here: MVC 4 Beta side by side installation error
Your problem is different, but I would probably start with web.config
You may have had setting in vs 2010 mvc 3 like this:
<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>
Now perhaps it looks like this?
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

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>

MVC MiniProfiler with ASP.NET MVC 4

After adding MVC MiniProfiler to my ASP.NET MVC 4 project, it complains about requiring System.Web.Mvc 3.0.0.0.
Is there any way to use MiniProfiler with ASP.NET MVC 4?
The following assembly redirect is already defined in web.config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
I just created a new asp.net mvc 4 project and used nuget to grab the latest miniprofiler package. It started up just fine. Have you tried this? If you are using nuget, perhaps you should try to remove the mini profiler and then test, then add it back.
On difference in my project however is that my assemblyIdentity line includes a culture:
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
What setting do you have for MvcBuildViews in your project file? If your build error message is whingeing about a view try setting MvcBuildViews to false to get you through the compilation stage, then the binding redirect to MVC 4 should likely work as expected at run time.
BTW, to edit the MvcBuildViews setting you'll have to unload the project and edit the .proj file direct, you can't change this setting via the project settings screen in VS.
Have you tried adding an assembly binding redirect for System.Web.Mvc?

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>

Resources