MVC MiniProfiler with ASP.NET MVC 4 - mvc-mini-profiler

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?

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. :(

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>

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