Razor intellisense not working with custom ASP.NET MVC build - asp.net-mvc

I was able to create a custom build of ASP.NET MVC and use it in a web application, however, I can't seem to figure out how to get the Razor intellisense to work correctly.
If you follow the steps below, the Razor intellisense will only show WebPages info and nothing else (HTML helpers etc.).
I'm using VS 2012.
Here's what I've done so far:
I cloned the latest ASP.NET Web Stack
Opened the Runtime.sln and built the solution
Created a new ASP.NET MVC 4 (.NET 4.0) web application
Deleted existing references for System.Web.Mvc, System.Web.Razor, System.Web.WebPages, System.Web.WebPages.Razor, System.Web.WebPages.Deployment and added references to the built assemblies in step #2.
In ~/Views/Web.config, replaced System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 with just System.Web.WebPages.Razor
Also, replaced System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 with just System.Web.Mvc
Removed the following from the web.config
<runtime>
<assemblyBinding xmlns="urn:schemasmicrosoftcom:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<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>

If you're looking for intellisense support in VS 2012 for views, as well as the right-click context menus for the controllers folder and views folder (shortcuts to add controller and add view) then you need to open up the .csproj file of your web project and manually edit it to include the MVC project type GUID. This is what VS actually uses to decide what flavor of intellisense you get (among other things).
Specifically, the xml tag of the .csproj file you're looking for is:
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
You should be missing the GUID value
{E3E379DF-F4C6-4180-9B81-6769533ABE47}
Good luck!

Related

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ASP.NET MVC

I went through many answers that answered before but I'm not lucky to find a solution of my problem. This Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and many others I used.
****Here is the runtime error:****
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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: 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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/menupoly/abdulla/men1/MenuSnaps/
LOG: Initial PrivatePath = C:\menupoly\abdulla\men1\MenuSnaps\bin
Calling assembly : Microsoft.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\menupoly\abdulla\men1\MenuSnaps\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL.
LOG: Attempting download of new URL file:///C:/menupoly/abdulla/men1/MenuSnaps/bin/System.Web.WebPages.Razor.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: 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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
Microsoft.Web.Helpers.PreApplicationStartCode.Start() +0
[InvalidOperationException: The pre-application start initialization method Start on type Microsoft.Web.Helpers.PreApplicationStartCode threw an exception with the following error message: 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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +613
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531
[HttpException (0x80004005): The pre-application start initialization method Start on type Microsoft.Web.Helpers.PreApplicationStartCode threw an exception with the following error message: 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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9946024
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
**This is the portion of my Web.Config**
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
I verified the version of each on Reference are the same as on Web.Config. Please help me. Thank you for your help.
You have this binding redirection in web.config which mentions Razor 2.0 is being used instead of Razor 3.0, and you're trying to use Razor 3.0 assembly which not bound to anything:
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
The first thing you should do, change the binding redirection to use version 3.0 instead:
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Also ensure that these configuration lines exist in web.config inside Views folder:
<configSections>
<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>
If it still doesn't work & you're not sure that Razor package is properly installed, try reinstall the required packages with NuGet Gallery/Package Manager Console command (with -reinstall switch), then do given step above:
Update-Package –reinstall Microsoft.AspNet.WebPages
Update-Package -reinstall Microsoft.AspNet.Razor
NB - This assembly binding indicates that MVC 4 is being used:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
I recommend to upgrade your MVC project to version 5.0.0 and update Razor bindings to version 3.0.0 as suggested in this reference:
How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 (Microsoft Docs)
Similar issues:
Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0
Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0
Before trying anything else,
I would suggest removing all files from the bin and obj folder Manually to ensure the new build generates files what is referred to in solution.
Usually, this happens when changing branches from shared projects/main projects.
Hope that saves some efforts in the world of .NET
I was getting the same error few days ago. After searching for one whole day I found the solution.
May be this could help you.
1. Check your Server's Path "C:\Program Files (x86)\Microsoft ASP.NET".
Is there any folder named "ASP.NET MVC 4" ?
2. If not you need to install ASP.NET Framework 4 in your server.
(if your project is in Framework 4.0)
When you encounter this kind of error related to MVC while deploying your app on a IIS server which is not the development machine, this is because you probably don't have the MVC runtimes installed on the target machine.
You can have a look to the folder C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4 of your server. You should find inside a few folders, including an "assemblies" one.
If not, you can download the runtimes from MS website. I THINK this one could work :
https://www.microsoft.com/en-us/download/details.aspx?id=30683&751be11f-ede8-5a0c-058c-2ee190a24fa6=True but you'll have to check.
You should also be able to install MVC from Web Platform Installer.
Alternatively, you can also avoid to install the runtimes if you do not wish or if you can't :
To make your application work without the requested runtimes on server, in the "References" folder of your visual studio, you can select all offending assemblies, and for each of them, set to "True" the "Copy local".
You will have to do this for the MVC dll, but probably for a few others, for example : System.Net.Http, System.Net.Http.Formatting.dll, System.Net.Http.WebRequest, System.Web.Http.dll, System.Web.Http.WebHost.dll, etc.
So it will maybe require a few tries (fortunately you just have to read the error message at startup to get the name of the "next" missing DLL).
There is another possible cause. I just had this same error today. Basically, I imported a helper project from one solution to another, and then I got this error, even though the only web project in the new solution is an old WebForm! No razor at all!! Eventually, I realized one files in the helper project had a little code for helping process MVC drop down lists, and the helper project had a reference to System.Web.MVC. That was not needed in the new solution, so deleting that one file & the reference to System.Web.MVC solved the problem.
I had the same issue, but could not fix it for 3 days. I tried deleting .vs directory, trying with Visual Studio 2017 and 2019, removing references but the error was here:
In the bin directory, somehow (probably from the batch scripts we are using to build MS solutions) System.Web.Mvc.dll was there, and apparently it was loaded when WebForms solutions was started. After deleting the whole bin/ directory the WebForms started ok.
One problem was that I could start the WebForms solution using IIS Express, but Local IIS, but that's probably another type of problem.
Add System.Web.WebPages.Deployment.dll, System.Web.WebPages.dll, System.Web.WebPages.Razor.dll manually to the References folder

Error when upgrading glass mapper

Currently i have glass mapper v3 and in process of upgrading to latest glass mapper i.e. v4, however when i build the project its giving me following error.
Severity Code Description Project File Line Suppression State
Error CS1705 Assembly 'Glass.Mapper.Sc.Mvc' with identity 'Glass.Mapper.Sc.Mvc, Version=4.2.1.188, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc' with identity 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Here is the table of support versions of MVC with Sitemap versions. 8.1 and 8.2 support 5.2 MVC.
https://kb.sitecore.net/articles/087164
The latest glass mapper may not work with the older versions of Sitecore.
You can upgrade your MVC to 5.2 and add bindings to your web.config to make requests to 5.1 work on 5.2.
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" 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-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>

When I update ASP.NET MVC from 5.0 to 5.1, do I need to update the bindingRedirect to 5.1?

Should this...
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
...become this?
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
Or should I leave it alone?
What about when I update Razor from 3.0 to 3.1?
Should this...
<add key="webpages:Version" value="3.0.0.0" />
...become this?
<add key="webpages:Version" value="3.1.0.0" />
Or should I leave it alone?
What about when I go from 5.1.1 and 3.1.1 respectively? Should I be as granular as possible in my web.configs, or leave them at their major revisions? It seems to work both ways!
Late add:
And what the heck is going on here?
It says 5.1.1 in the path to the assembly, but 5.1.0.0 in the Version. Which number should I be using in the Web.config?
Yes to MVC, no to WebPages. WebPages assembly version did not change, it was only a NuGet package version upgrade.
On Web.config always use the assembly version, not the package version. I don't think they'll use the patch part on the assembly version, only on the package version.

how to use DotNetOpenAuth.Core, Version=4.3.0.0 with vs 2012

i'm using visual studio (2012 or 2013) with asp mvc 4
and it gives me the following error :
Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
i need to use version 4.3.0.0 i installed it using nuget
I know I had problems with the System.Mvc dependency being of the wrong version. Adding the following assembly "rebinding" to your web.config solved the problem (note the version numbers):
<configuration>
<runtime>
<!-- When targeting ASP.NET MVC 3-4, this assemblyBinding makes MVC 1 and 2 references relink
to MVC 3-4 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it. -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Sidenote: I discovered DotNetOpenAuth.Ultimate that bundles everything into one single DLL! It's much much simpler to maintain that the default DotNetOpenAuth and its huge number of packages....

Why is Combres still looking for an older version of System.Web.Mvc?

I'm using Combres with my MVC 3 RC project and getting an an assembly binding error when I deploy it to my web server.
System.IO.FileLoadException
Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
<%= Html.CombresLink("commonJs") %>
My development machine has the MVC 1 and 2 assemblies in the GAC, so it works fine there. The web server doesn't have any version of MVC in the GAC, and I'm bin-deploying the MVC 3 assembly. My project references version 3.0.0.0 of System.Web.Mvc, and I have the following section in my 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>
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I thought that this section would tell Combres to use version 3.0.0.0 instead. Why is my application failing to resolve the reference?
I don't think the binding redirect will chain - you have a reference to 1.0 somewhere, and your config tells it to load 2.0, which does not exist.
You need just one binding redirect with oldVersion set to "1.0.0.0-2.0.0.0"

Resources