34

I want using external logins so I installed Oauth by package manager:

 PM> Install-Package Microsoft.AspNet.WebPages.OAuth

Then I got this error after installed it then I install razor:

PM> Install-Package Microsoft.AspNet.Razor

But I still have this exception. Further more my application is an asp.net application and not a MVC application. Thanks for help.

[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +0
Hamid Bahmanabady
  • 665
  • 1
  • 8
  • 20
  • When you say an aspp.net application; do you mean Webforms? Because MVC is still an asp.net application. As it goes; Razor is an MVC scripting language. If you are not building an MVC app; then it is no wonder you are having issues. Honestly; you answered the question yourself. – Dave Lawrence Nov 04 '13 at 07:26
  • Is your project based on .net4. Many component of Razor 3 maybe based on 4.5. Check my answer. – Anirudha Gupta Nov 04 '13 at 08:09

6 Answers6

16

Apologies in advance for this lo-tech suggestion, but another option, which finally worked for me after battling NuGet for several hours, is to re-create a new empty project, Web API in my case, and just copy the guts of your old, now-broken project into the new one. Took me about 15 minutes.

  • 2
    15 minutes vs hours of headache, thats great – Ruchan Aug 03 '15 at 12:29
  • similarly, in the TFS project, i shelved my changes, cloaked the branch, deleted the existing files, remapped the project, got the latest version and then re-merged from the shelfset. I think it's the same idea that you are suggesting. It took me an hour to reset everything this way, after almost a day of struggling with the NuGet packages being all jacked on my local environment. – stephenbayer Mar 10 '17 at 20:00
12

You have upgraded to Razor 3. Remember that VS 12 (until update 4) doesn't support it. Install The Razor 3 from nuget or downgrade it through these step

geekswithblogs.net/anirugu/archive/2013/11/04/how-to-downgrade-razor-3-and-fix-the-issue-that.aspx

Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
  • Hi I installed razor 3 but does not add **System.Web.WebPages.Razor version 3** and I still have the exception – Hamid Bahmanabady Nov 04 '13 at 09:27
  • 1
    Razor 3 dependencies are based on .net 4.5. You can't get it worked if your project is deployed in .net 4. In MVC 4 (that will work also in .net 4 we use Razor 2. If you have trouble then I simply recommended you to deploy your app in .net 4 (mvc4) and it will work simply :) – Anirudha Gupta Nov 04 '13 at 09:32
  • If your problem still remain then make backup and remove all that come with mvc 4. run this nuget https://www.nuget.org/packages/UpgradeMvc3ToMvc4 and you will got your project running in MVC 4. – Anirudha Gupta Nov 04 '13 at 09:33
10

Another option is to update the Microsoft.AspnNet.Mvc NuGet package. Be careful, because NuGet update does not update the Web.Config. You should update all previous version numbers to updated number. For example if you update from asp.net MVC 4.0.0.0 to 5.0.0.0, then this should be replaced in the Web.Config:

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>
Gašper Sladič
  • 867
  • 2
  • 15
  • 32
  • Believe it or not... This was the answer that finally got my MVC application updated to MVC 5.2.6 with Razor 3.2.6. If you have Areas you will need to change the web.config files in each view folder of your Areas, and also the root View folder if you have one. – Rod Hartzell Jul 18 '18 at 23:01
5

Update using NuGet Package Manager Console in your Visual Studio

Update-Package -reinstall Microsoft.AspNet.Mvc
Community
  • 1
  • 1
0

What worked for me is: right click on project properties then Manage Nugget Packages then chose update tab then chose Microsoft.AspNet.Razor then downgrade to version 3.0.0

Khalid
  • 343
  • 3
  • 16
0

I went a little bit further. My project is pretty big and I refuse to create a new project and then move everything from the old to the new. Boring.

My solution
I forced NUGET to reinstall everything, I took the names from the project file under 'Import Project=...', removed the '.props' extension. Open the NUGET console on the V/Studio Tool Menu:

On my project (partial)

Update-Package -reinstall Microsoft.Net.Compilers.Toolset
Update-Package -reinstall Microsoft.Net.Compilers
Update-Package -reinstall Microsoft.CodeAnalysis.Analyzers
Update-Package -reinstall Microsoft.TypeScript.MSBuild
Update-Package -reinstall EntityFramework
Update-Package -reinstall Microsoft.TypeScript.Default
Update-Package -reinstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Update-Package -reinstall Microsoft.Common
Update-Package -reinstall Microsoft.TypeScript.MSBuild

Finnaly
And then, on the same project file, I deleted all the lines containing <Error Condition="!Exists('packages.... to avoid compiler missing package failure .

My project and solutions are now up and running.

fcm
  • 1,247
  • 15
  • 28