'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink
asp.net, asp.net-mvc, c#, razor
Solution
I'm working with VS 2013 Pro Update 2. This is what worked for me:
- Close Visual Studio
- Delete bin and obj folders
- Reopen your solution and rebuild
- No more errors on the view
BTW there is no need to change anything on configuration files and a simple clean and rebuild solution does not work.
Problem
Firstly - I have scoured SO and found many questions asking the same thing, though simply adding `<add namespace="System.Web.Mvc.Html" />` in my web.config didn't cure the issue... Ok, so I have started a new project, based on the template Angular SPA - link is here: http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83 I have upgraded the MVC to version 5 & the webApi to version 2 - to fall in line with other projects in the solution. Now, in the _layout page of the SPA site I am trying to use the `@Html.ActionLink` helper, though keep getting the error `'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink` I am sure this is all down to some web.config configuration - some kind of conflict between what packages I have installed and what is setup in the config from the template. In particular, this part: ``` <system.web.webPages.razor> <host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.WebPages.WebPage"> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Optimization" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web.webPages.razor> ``` If I change this to use version 5 then I get the error that the assembly (v5) could not be located etc. I am running out of ideas on how to resolve this conflict. Here are the config sections from my SPA 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> ``` If I change the version to 5, I get the error below: ``` Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded. === Pre-bind state information === LOG: DisplayName = System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///D:/Development/IS/IS/IS.TransactionDesk.SPA/ LOG: Initial PrivatePath = D:\Development\IS\IS\IS.TransactionDesk.SPA\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\Development\IS\IS\IS.TransactionDesk.SPA\web.config LOG: Using host configuration file: C:\Users\Darren\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=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/Darren/AppData/Local/Temp/Temporary ASP.NET Files/root/3407d437/8e7ba9a/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///C:/Users/Darren/AppData/Local/Temp/Temporary ASP.NET Files/root/3407d437/8e7ba9a/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///D:/Development/IS/IS/IS.TransactionDesk.SPA/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=5.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.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70 System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39 System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +37 System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65 System.Web.WebPages.Razor.WebRazorHostFactory.DefaultTypeFactory(String typeName) +39 System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(String typeName) +67 System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup config, String virtualPath, String physicalPath) +313 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath, String physicalPath) +228 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath) +38 System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig() +51 System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +57 System.Web.WebPages.Razor.RazorBuildProvider.get_Host() +56 System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode() +77 System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType() +54 System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +59 System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +209 System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +30 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +9881909 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +165 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +43 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +28 System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +343 System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +236 System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +261 System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +132 System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +58 System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath) +59 IS.TransactionDesk.SPA.Routing.DefaultRouteHandler.GetHttpHandler(RequestContext requestContext) in d:\Development\IS\IS\IS.TransactionDesk.SPA\Routing\DefaultRouteHandler.cs:42 System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9598252 System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69 ```