I am trying to use FxCop on a project that has been upgraded from MVC 1 through MVC 3. The first time I ran my project, it asked me to locate MVC 3 for it. Once I did, it continued on for a bit and then asked me to find MVC 1, which I find odd because I no longer have it installed on this machine and the website operates just fine. This is the message it is giving me:
In our Web.config file we have the following, which is created automatically when you upgrade versions of MVC:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Does anyone have any idea how to get rid of this error so FxCop will complete it's analysis of this project?
Got same problem with FxCop. Have you checked other assemblies, that might be dependant on MVC1? AFAIK MVC1 required 3 assemblies:
System.Web.Mvc
System.Web.Routing
System.Web.Abstractions
Maybe Routing or Abstractions left somewhere in your references?
As a workaround to get FxCop going you can update the FxCop configuration and set the following:
<appSettings>
<add key="AssemblyReferenceResolveMode" value="StrongNameIgnoringVersion" />
</appSettings>
Its most likely currently set to StrongName.
The allowable values are:
None - Do not match strong names at all, any assembly with the same file name is considered a match.
StrongName - Strong names including assembly name, version, culture and public key token must exactly match.
StrongNameIgnoringVersion - Strong names including assembly name, culture and public key token must exactly match. Assemblies with an equal or greater version are considered a match.`
However I would look at your assembly with something like DotPeek to try to determine why its still referencing the older version.
Related
I have a VS 2012 Web Project Up. I have ODP.NET installed as we are an Oracle Workshop. I inherited a project that uses Oracle.ManagedAccess.Data and EF.
Upon running the project in VS 2012, I get the following error:
There is a duplicate 'oracle.manageddataaccess.client' section defined..
The solution was to disable the following line in web.config
<!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->
Which was fine. The project compiled but upon executing a simple command such as getting a password back where it has to read the database another error was tripped up:
System.Data.ConstraintException: Column 'InvariantName' is constrained to be unique. Value 'Oracle.ManagedDataAccess.Client' is already present.
Now I'm aware that the error is tripped up by ODP.NET and having it exist in the GAC thus the double error reporting.
Is there another line I should be commenting out or is there a way to disable ODP.NET briefly? I don't want to install that client as I use it for other projects.
thanks
I found the following on the Oracle site regarding the "There is a duplicate 'oracle.manageddataaccess.client' section defined.":
If your application is a web application and the above entry was added
to a web.config and the same config
section handler for "oracle.manageddataaccess.client" also exists in
machine.config but the "Version" attribute values
are different, an error message of "There is a duplicate
'oracle.manageddataaccess.client' section defined." may be
observed at runtime. If so, the config section handler entry in the
machine.config for "oracle.manageddataaccess.client" has to be removed from the machine.config
for the web application to not encounter
this error. But given that there may be other applications on the machine
that depended on this entry in the
machine.config, this config section handler entry may need to be moved to all
of the application's .NET config file on
that machine that depend on it.
I hope it helps.
I was getting the same error for an ASP.Net MVC project. I found that there is a version mismatch for oracle.manageddataaccess.client in the Web.config of the project, and machine.config in
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config, and
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config.
I had Version=4.122.18.3 in the Web.config and Version=4.122.1.0 in the machine.config.
I updated the version(replaced Version=4.122.1.0 of oracle.manageddataaccess.client with 4.122.18.3) in both the machine.config, and the problem resolved.
In my case I have multiple projects. One a Entity Framework data model, another which is an WCF Service using the EF Model, a WPF project using the WCF Service, and finally, my ASP.NET MVC prject, using the Entity Framework Data model directly.
We use Oracle and had a Nuget package oracle.manageddata. I used Version 12.1.21 in all the others, except my ASP project (which had version 12.1.22). After downgrading to what the other projects are using, my Web ASP is running again. Using different Nuget versions in various projects, in the same solution, doesn't seem to be such a good idea.
There are multiple ways to solve this problem. Not everyone has the luxury or desire to modify the machine.config (especially on a server). Perhaps the easiest way to solve this problem is to use bindingRedirect in your web.config (or app.config, if not a web application).
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.122.21.1" newVersion="4.122.21.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
NOTE: The version I am using is 4.122.21.1. Be sure you match your own version that you are using.
NOTE: The redirect is on Oracle.ManagedDataAccess, not Oracle.ManagedDataAccess.Client; this is a common mistake that developers make.
If you want to make the change in the machine.config, proceed carefully as this could have unanticipated consequences on other apps on the machine. The simplest modification is to change the version of the Oracle.ManagedDataAccess.Client section from a strong version to any version by using an asterisk "*".
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=*, Culture=neutral, PublicKeyToken=89b483f429c47342" />
If you need additional clarification, let me know and I can give more details.
In my ASP.Net MVC 5 application using VS 2013, I am using Unity MVC bootstrapper [package id="Unity.Mvc"] which is in other dll. Not sure, which is not working.
The similar setup is working VS 2012 + ASp.Net MVC 4 application and same package.
Can some body help me in resolving this? Is unity bootstrap is compatible with Asp.Net MVC 5?
My bad. Thanks for the responses. It is something wrong with my setup. My output binary (dll) is not copying into the web project folder as I gave the folder path wrong while upgrading. One more issue I observed to resolve is system.Web.http binding is failing. So I need to have the bind attribute in my web.config file.
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
</assemblyBinding>`
I'm working in an Asp.net MVC 4 project in Visual Studio 2012, when I open a view I'm getting this error:
ASP.NET runtime error: The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.. C:\Users\escobar5\Desktop\WindowsAzure1\MvcWebRole1\Views\Shared_LoginPartial.cshtml
So I lost intellisense because after that error every call to ViewBag or model says: "One or more types required to compile a dynamic expression cannot be found"
I updated OAuth packages from Nuget but I'm still getting the error.
The project runs fine, the problem is just with razor.
This is a screenshot of the error for more detail:
Any ideas?
Thanks in advance
I found the following explanation and updating DotNetOpenAuth.OAuth.Consumer with nuget package manager solved the problem with the error.
https://groups.google.com/forum/?fromgroups=#!topic/dotnetopenid/js58kMaWvvo
I found as soon as I added log4net via NuGet to my application that while the error has not gone away, Intellisense works in the file.
It looks like the Reporting module of DotNetOpenAuth relies on a class called Logger, which in turn relies on log4net.
The wrong project was selected in the Package Manager Console.... my stupid mistake. Guess I should have had more coffee before working on this.
I solved this by going into the Manage NuGet Packages for Solution and clicking Manage next to ASP.NET MVC 4, then adding that package to the MVC4 project in the solution.
I had to perform the following two steps to resolve this issue.
Update the DotNetOpenAuth.OAuth.Consumer NuGet package. Credit to Magnus Karlsson for this bit - see his answer for further details.
Remove the assembly binding for System.Web.Razor from the Web.Config file. This is from rana's answer.
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
If you have this line in your web.config file
<add key="webpages:Enabled" value="true" />
then remove it.
Is there a way to have a project use MVC1 in certain areas and use MVC3 in other areas?
I have some previous code written but I was thinking of using MVC 3 to add other features.
Thanks.
Have you tried just upgrading? What things do you need from MVC1 that you can't use in MVC3? There are breaking changes, but it's very likely that you won't run into any of them, or that you can upgrade those parts of your code to run the entire app on MVC3.
No, there is no way to mix ASP.NET MVC 1 and ASP.NET MVC 3 in the same ASP.NET application. And that's a good thing because you should never even attempt to do this. They should be in separate applications if migration is not an option for you at the moment.
As per my knowledge I think we can use MVC1 code by adding following code in web.config file.
<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>
Please correct if I am wrong.
I have got a question with regards to upgrading asp.net mvc applications from v1 to v2...
I've noticed in the ASP.NET MVC v2 Release notes that we need to add this code (please see below) when upgrading, but it did not state what would be the purpose of it because I've tried experimenting some of my apps to asp.net mvc 2 without adding this particular section in 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" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Would there be implications should I not place this?
Thanks!
What this code does is pretty much tells your entire project that if there happen to be any old leftover references to MVC 1.0, then it should instead go try and use the 2.0 version instead. And I believe this would be inherited by class libraries as well where you might forget to update references.