If you encounter a version problem again, record it, forget it, and forget it.
It took a long time to find the solution. It took more than two hours! Record again, Memo!
Problems in ASP. net mvc may occur due to two reasons:
I have referenced the master program High Version dll in the newly created Project. The versions are inconsistent.
A series of problems occurred during version upgrade between MVC4 and MVC5
1. System. Web. WebPages. Razor. Configuration. HostSection version
[A] System. Web. WebPages. Razor. Configuration. HostSection cannot be forcibly converted to [B] System. Web. WebPages. Razor. Configuration. HostSection. Type A is derived from "System. web. webPages. razor, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "(in the Context" Default "," C: \ Windows \ Microsoft. net \ assembly \ GAC_MSIL \ System. web. webPages. razor \ v4.0 _ 1.0.0.0 _ 31bf3856ad364e35 \ System. web. webPages. razor. dll ). Type B is derived from "System. web. webPages. razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "(in the Context" Default "," C: \ Windows \ Microsoft. net \ assembly \ GAC_MSIL \ System. web. webPages. razor \ v4.0 _ 2.0.0.0 _ 31bf3856ad364e35 \ System. web. webPages. razor. dll ).
Solution:Configure Web. config in view<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 "/>
2. System. Web. WebPages. Razor. Configuration. RazorPagesSection
[A] System. Web. WebPages. Razor. Configuration. RazorPagesSection cannot be forcibly converted to [B] System. Web. WebPages. Razor. Configuration. RazorPagesSection. Type A is derived from "System. web. webPages. razor, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "(in the Context" Default "," C: \ Windows \ Microsoft. net \ assembly \ GAC_MSIL \ System. web. webPages. razor \ v4.0 _ 1.0.0.0 _ 31bf3856ad364e35 \ System. web. webPages. razor. dll ). Type B is derived from "System. web. webPages. razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "(in the Context" Default "," C: \ Windows \ Microsoft. net \ assembly \ GAC_MSIL \ System. web. webPages. razor \ v4.0 _ 2.0.0.0 _ 31bf3856ad364e35 \ System. web. webPages. razor. dll ).
Solution:Configure Web. config in view<Section name = "pages" type = "System. web. webPages. razor. configuration. razorPagesSection, System. web. webPages. razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31BF3856AD364E35 "requirePermission =" false "/>
3. System. Web. Mvc. MvcWebRazorHostFactory version Problems
The expression "System. Web. Mvc. MvcWebRazorHostFactory" cannot be used to return the type "System. Web. WebPages. Razor. WebRazorHostFactory"
Solution:Configure Web. config under the project<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> --> <dependentAssembly> <assemblyIdentity name =" System. web. helpers "publicKeyToken =" 31bf3856ad364e35 "/> <bindingRedirect oldVersion =" 1.0.0.0-2.0.0.0 "newVersion =" 2.0.0.0 "/> </dependentAssembly> <assemblyIdentity name =" System. web. mvc "publicKeyToken =" 31bf3856ad364e35 "/> <bindingRedirect oldVersion =" 1.0.0.0-4.0.0.0 "newVersion =" 4.0.0.0 "/> </dependentAssembly> <assemblyIdentity name =" System. web. webPages "publicKeyToken =" 31bf3856ad364e35 "/> <bindingRedirect oldVersion =" 1.0.0.0-2.0.0.0 "newVersion =" 2.0.0.0 "/> </dependentAssembly> </assemblyBinding></Runtime>
You can leave a message on the public account to obtain related resources or ask other questions.If you have excellent original technical articles, you can contribute articles and share them with others to earn a reward!
Scan to get more development resources: