Build Errors - 'System.Web.Mvc.ModelClientValidationRule' Conflicts - asp.net-mvc

I am trying to 'build' my MVC3 web app in VS2010 however keep getting the following error:
Error 2 The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' and 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' C:\Users\brownp\Documents\Visual Studio 2010\Projects\Cab\Cab\Models\AccountModels.cs 223 28 Cab
Also, every time I open the solution, it prompts me with the following:
I install via Web Platform Installer and it installs successfully however the message reappears every time I open the solution.
Can anyone offer any guidance?
Thanks Paul

After installing MVC4 beta today, a few of my MVC 3 projects would not compile. (ModelClientValidationRule conflict) The fix was:
Edit:
ProjectName.csproj
Change
<Reference Include="System.Web.WebPages"/>
To
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>

Ok try this solution...
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
3.Locate the following assembly references:
<Reference Include="System.Web.WebPages"/>
<Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
4.Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
REFERENCE: http://forums.asp.net/t/1723108.aspx/1
also try: http://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253815

Delete System.Web.WebPages from solution references. It is all.

The best way to avoid this conflict is-
Go to solution explorer
Reference
Right click on System.Web.WebPages
Remove
Now run your application and Enjoy !

This issue, which is the same as you described in VS2010, occurred in my case in VS2015 with a newer version of MVC (V5).
Here's how I was able to fix it:
Update the NUGET packages to the latest version.
In your project, remove the references for Microsoft.AspNet.WebPages. Then, re-add reference by using the latest package (use "Browse..."):
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40
Ensure that all projects are referencing the same assembly, if not, fix them as described above. Then, re-build the solution. In my case, it fixed the error.
Check the Web.config file, and fix settings such as:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="true" />
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

Related

EF6 + NPGSQL - App.Config Settings - Provider with invariant name 'Npqsql' is either not registered etc. etc

Visual Studio 2015 / .NET Framework 4.5
EntityFramework v6.1.3
EntityFramework6.Npgsql v3.1.0
Npgsql 3.2.2
I have inherited a project which contains and EDMX EF6 model which I cannot open in Visual Studio (although the code runs OK) possibly (??) because I am getting the following error: -
"Error 175: The ADO.NET provider with invariant name 'Npgsql' is
either not registered in the machine or application config file, or
could not be loaded. See the inner exception for details."
The relevant app.config settings look like this: -
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"/>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF"/>
</DbProviderFactories>
</system.data>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.2.0" newVersion="3.2.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
The Schema line from the EDMX looks like this :-
<Schema Namespace="MyAppMOdel.Store" Alias="Self" Provider="Npgsql" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
I am a bit wary of the ProviderManifestToken="4.0" setting since this project was previously using SQL Server Compact 4. What would be the correct value here?
Any ideas on what's wrong?
Thx!
It looks like someone had made some changes by hand:-(
After a lot of faffing (was having trouble with Data Connections & the EDM wizard https://github.com/npgsql/npgsql/issues/1445) I could see that the ProviderManifestToken should have been "9.6.2"; with that change made my EDMX I am now able to open it withing Visual Studio 2015.
The line in the EDMX file now looks like
<Schema Namespace="MyAppModel.Store" Provider="Npgsql" ProviderManifestToken="9.6.2" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">

VS 2015 : Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0

I am running a solution which contains different projects. However, i am trying to run a project (class library) which contains wcf services using Visual Studio 2015 and framework 4.6 (on windows 8 OS, IIS Express). However it keeps showing this error in the browser:
Error:
I noticed that the calling assembly of Razor 2.0 is "System.Web.Mvc" Version 4.0.0.1:
Calling assembly : System.Web.Mvc, Version=4.0.0.1, Culture=neutral,
PublicKeyToken=31bf3856ad364e35.
However, System.Web.MVC dll is not referenced in this project, the references in the project are in the image below:
Although, it is not referenced it always appears in the bin folder, even when i clear it. And may be that's why it is trying to call "System.Web.WebPages.Razor" version 2.0.
Clarifying any clues of the problem:
I have no related assembly in the Web.Config that calls System.web.mvc
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
also not included in package config:
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="Microsoft.AspNet.Providers" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
<package id="PostSharp" version="4.3.5-alpha" targetFramework="net46" />
<package id="System.Web.Providers" version="1.2" targetFramework="net451" />
</packages>
not included as a reference
I am wondering about whats going on? may another project affects it!
Also i have tried to use nugget to update the packages (uninstalled and reinstalled), but still in the same situation.
A possible reason of the problem:
I also noticed there is a "Gobal.asax" file in this project which uses "MvcApplication" class that implements "System.Web.HttpApplication" which may be a good reason of the problem.
Any help is appreciated.
Solution: install Microsoft.AspNet.Webpages first release of version 2.0 via nuget manager.
I would start by looking at assembly binding failures - this will show you which assembly is requesting that failing binding.
There is a handy little tool you can use to view your binding failures. This should help you track it down.
https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx
Good luck!
in my case, the error was after deploying, and the issue was a reference in a web.config within a sub folder of that server.
i troubleshot this by remoting into that machine and browsing the site locally (or you can enable remote errors in web.config)
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
So be sure to search all your files for 2.0.0.0 or System.Web.WebPages.Razor to make sure there is no reference somewhere!
I was getting this error, but the project from which the error is throwing has the Microsoft.AspNet.Webpages installed properly. Then I realised that the WCF services which are kept in a separate project lost it's MVC installation.
So installing Microsoft.AspNet.Mvc in my other project fixed this error for me.

Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, or one of its dependencies

Please somebody help me fix this issue.
Umbraco application as parent on IIS6 has the following version of System.Web.WebPages.Razor.
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
<system.web.webPages.razor>
<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor" />
<pages pageBaseType="System.Web.WebPages.WebPage">
<namespaces>
<add namespace="Microsoft.Web.Helpers" />
<add namespace="umbraco" />
<add namespace="Examine" />
</namespaces>
</pages>
Blog Engine application as virtual directory under the Umbraco application on IIS6 has the following version of System.Web.WebPages.Razor.
<configSections>
<remove name="system.web.webPages.razor" />
</configSections>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Even after i added the dependentAssembly still nothing works for me, Am wasting more than a week on this issue, Please help.
Have you checked the actual version of System.Web.WebPages.Razor that is currently deployed to your bin folder? I had a similar issue recently in a multi-project solution and one of the projects was using an older version of the assembly via Nuget which happened to be the one that ended up in the bin folder causing a similar error. In fact I'm pretty sure that it's the Umbraco Nuget package copying in the older assembly.
Finally, I have fixed this issue. Blog Engine's(Child application) Razor Script version is 2.0.0.0 and Umbraco(Parent application) 4.1.6 application's Razor script version is 1.0.0.0, i have added the below in child's web.config
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Once the above added, i get rid of this error and i faced the same dependency errors for the below and i added the respective dependent assembly and the version.
Microsoft.Web.Helpers.dll
Examine.dll
Umbraco.dll
WebGrease.dll
For the above three dependency will not present in child application's bin folder, you need to copy the dll files from parent bin folder and add it in child bin folder, which will sort all the dependency issues.
For any deploying issues on BlogEngine as virtual directory and Umbraco as parent application, leave your message will help you solve the issue of any different versions.
#ProNotion is right, I have seen more and more packages on Umbraco relying on specific versions of assemblies causing assemblies to conflict especially if two packages need different versions of the same assembly.
So some other tips:
This tool from MS helps diagnose assembly binding problems (http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx).
Adding a runtime / assemblyBinding section to your web.config can work round problems with clashing assemblies (http://msdn.microsoft.com/en-us/library/0ash1ksb(v=vs.110).aspx)
Sometime the assembly doesn't get copied (eg you use msbuild and the assembly isn't included in the project) - so you should also check to see if the assembly made it to the live server.
Please try the following steps.
Check the Version of System.Web.Webpages in your References. Say Your Version is=X.X.X.X
2.In Webconfig
a.Add the assembly first
<assemblies>
<add assembly="System.Web.WebPages, Version=X.X.X.X, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
b.Bind the assembly for runtime
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-X.X.X.X" newVersion="X.X.X.X"/>
</dependentAssembly>
</assemblyBinding>
3.Make sure you have added correct key
<appSettings>
<add key="webpages:Version" value="X.X.X.X"/>
</appSettings>
This worked for me. Hope It'll help you too.
Sometime, you will have mistake between
System.Web.WebPages.Razor
and
System.Web.Razor
Try look and check
Create a new Area, right click project, Add, Area
Copy the web.config from the views folder in this area to /views/web.config
remove the area

Opening an MVC3 project in VS2012

I am trying to open an MVC3 solution in a newly installed Visual Studio Express 2012 RC. So far, I've had issues that for some reason VS2012 doesn't know that the projects are MVC projects, so it won't add Views/Controllers. Got past this by adding the following GUID to the ProjectTypeGuids node of the .csproj file of each project in the solution:
{E53F8FEA-EAE0-44A6-8774-FFD645390401}
However, when I open razor views, it shows these errors (among other related ones):
Error 20 The name 'model' does not exist in the current context c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 2 2 EventManagement
Error 21 The name 'T' does not exist in the current context c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 5 14 EventManagement
Error 22 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 6 11 EventManagement
Intellisense is working in the razor view, but it only gives limited amount of fields for the Html helper method. For instance, none of the model specific methods like LabelFor and TextboxFor.
I have MVC 3 and 4 installed. The solution worked fine in VS2010.
UPDATE:
When adding a new MVC3 project in VS2012, it works fine. So that means it is definately something to do with the project, and not the installation.
UPDATE 2:
I think that the issue is that the view doesn't have access to the referenced libraries in the root config:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Orchard.Mvc.Html"/>
</namespaces>
</pages>
</system.web.webPages.razor>
It does at runtime, but the intellilsense and error console doesn't pick it up
Any help is appreciated.
Thanks
For me this problem was resolved by adding:
<add key="webpages:Version" value="1.0.0.0"/>
in my appSettings section of my root web.config
e.g.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
Check this Link:
http://msdn.microsoft.com/en-us/library/hh266747(v=vs.110).aspx
Make sure you know that project is MVC3.
Make sure that project was created with VS2010 with SP1.
I fixed this by uninstalling MVC4 RC. Doesn't seem compatible with my system (or the 3 other systems I tested with). Will just have to wait for the release version of MVC4
From MVC 4 release notes:
Required updates
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
Locate the following assembly references:
< Reference Include="System.Web.WebPages"/>
< Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
4.List item
Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
You may install both MVC3 and MVC4 on the same computer, please configure in web.config like below
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

"Consider app.config remapping of assembly ..." warning in F#

After I installed VS11, I started to get the following error:
Consider app.config remapping of assembly "FSharp.Core, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "2.0.0.0" [C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0\FSharp.Core.dll] to Version "4.0.0.0" [C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll] to solve conflict and get rid of warning.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1490,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.
What exactly should I do? I have no idea how to do such a remapping.
Below is I think a sample app.config that does what is suggested. However, what is in your project, and what FSharp.Core reference is there? Are you targeting .Net 4.5 or 4.0 or what? Does this project reference some older F# library? This typically is because two projects reference different versions of FSharp.Core.dll, e.g. check the <Reference> nodes in the .fsproj files.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral"/>
<!-- <bindingRedirect oldVersion="0.0.0.0-2.9.9.9" newVersion="4.3.0.0"/> -->
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
same error related to Json.Net
In project file I had
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
and
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
Deleting the old one solved the problem.
If you have accomplished upgrade well, there should be no such issue... Unless you're using some third party library, that uses old FSharp.Core itself. In my case it's FSharpPowerPack who does this.
So you have to either update that library first to get rid of this message.

Resources