find a location for property in a new city

Friday, 6 May 2011

MVC3 deploy - Could not load file or assembly 'System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

Whilst deploying my newly upgraded ASP.NET MVC 3 web application to the production environment I started receiving a FileNotFoundException with the error message "Could not load file or assembly 'System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified." I have encountered this before so I know it is about bin-deploying that assembly. But where is the System.Web.WebPages.Razor assembly?

Since you have installed ASP.NET MVC 3 on your development machine you have all these MVC 3 assemblies installed in your GAC. Your production machine does not!

So you need to find this file and make it bin deployable however this cheeky assembly isn't in you solution so how can you do that? Well... add it. Go to Add Reference on your root web project (e.g. Web.csproj) and find System.Web.WebPages.Razor and add.

Now right click this assembly in your references directory and click properties.

Now you can make it bin deployable by setting Copy Local to true like so:

Note this is how to deploy the System.Web.WebPages.Razor assembly withe your ASP.NET MVC 3 web application. To deploy a typical setup of an ASP.NET MVC 3 app you will need to do the same for all of the following assemblies:
  • System.Web.Mvc
  • System.Web.Helpers
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor as detailed above
  • Microsoft.Web.Infrastructure this will also need a reference added as above
  • WebMatrix.Data this also needs the reference

Of course you only need to add the reference to these assemblies if they are not already there - in most cases it will be. This was mainly a blog post for the slightly more complicated System.Web.WebPages.Razor.dll


There is an easier way to do this if you are using Visual Studio 2010 Service Pack 1 and using Web Deploy as your publish action when publishing. You can add deployable dependencies to your ASP.NET MVC project that will choose the necessary assemblies for you. Even easier!

Follow britishdev on Twitter


  1. Thanks for this. Saved my team lots of time.

  2. Thanks! You got us fixed right up!!!!

  3. Thanks for this. Saved me lots of time!! I mean it!

  4. Wowwww... Perfect.. After 2 days reading heaps of blogs finally your blog solved my problem!! ;)

  5. You forget about "NuGet.Core" (you may notice in your other post - screenshot with this reference)
    Well, at least Azure force me to use it :)

    Thank you very much btw

  6. What worked for me was to right-click on the project and select Add Deployable Dependancies

    1. thank you for your advise, it helped me!

  7. Yes you can and it is much easier and works well (if you are publishing using Web Deploy). I wrote this post before SP1 had come out though (hence the update at the end of the post).

  8. I,m sorry, i.m a newbie in c# mvc3, i want to ask u, how to deploy my app in IIS7, what first I should do and What next? i need ur help, cz its urgently need...

  9. If it is so urgent, why is 'a newbie' in charge? Anyway, sorry I haven't got the time to train you to do the job you don't deserve but I have found a link that should help:

  10. thanks, helpful

  11. Thank you, very helpful

  12. Thanks Man! It help me to publish an application in a sub-domain.

  13. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan, Summer collection. Shipping worldwide. Stitching option available.

  14. I often use online converters to convert files (e.g. doc to pdf, tiff to jpg, etc.). The best in my ranking - AnyConv

  15. I think about it is most required for making more on this get engaged safety razor

  16. Awesome Insights Articles about issues and you saved me a hour. Here My question is about the Tech News Tamil Portal website hosting. I Running News Portal website at present I using Host raja hosting, shall I change to CDN server?

  17. Blackbird packaging provide you with any size, shape design, custom cbd tincture boxes sooner than any other packaging competitor in the market

  18. Great Article
    Cloud Computing Projects

    Networking Projects

    Final Year

    Projects for CSE

    JavaScript Training in Chennai


    Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

  19. I hope to see more news from you. Having email is a essential thing when you use internet, but to use email more effectively is not very easy when the instruction is updated and changed regularly for better experience and security, gmail sign in has the tutorial and tips you need.

  20. Shop electronics online in lahore Goods at Al-Fatah, Pakistan’s leading chain of departmental stores. Shop from a huge range of top brands Home Appliances, Smart-tech and Phones and Sound bars from Al-Fatah. Shop from huge range of electronics available at Al-Fatah. Avail Free Delivery on orders above 1000 PKR in selected cities.

  21. Buy microwave ovens online from Al-Fatah at best prices. Get free shipping.

  22. Buy sports bra online from Dshred at easy prices delivered at your doorstep. Get free shipping

  23. Buy lounge wear for mens from Dshred at best prices delivered at your doorstep. Get free shipping

  24. Buy gym trousers for men online from Dshred at best prices delivered at your doorstep. Get free shipping

  25. Buy gym trousers for men online from Dshred at best prices delivered at your doorstep. Get free shipping.vvv

  26. Buy men accessories online from Al-Fatah at best prices delivered at your doorstep. Get free shipping