Erstens - Ich habe SO durchsucht und viele Fragen gefunden, die dasselbe fragten, obwohl das einfache Hinzufügen von <add namespace="System.Web.Mvc.Html" />
in meiner web.config das Problem nicht behoben hat ...
Ok, also ich habe ein neues Projekt gestartet, basierend auf der Vorlage Angular SPA - Link ist hier:
http://visualstudiogallery.msdn.Microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83
Ich habe die MVC auf Version 5 und das webApi auf Version 2 aktualisiert, um mit anderen Projekten in der Lösung übereinzustimmen.
Jetzt versuche ich auf der _layout-Seite der SPA-Site, den @Html.ActionLink
-Helfer zu verwenden, erhalte jedoch weiterhin den Fehler 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink
Ich bin sicher, dass dies alles auf eine web.config-Konfiguration zurückzuführen ist - eine Art Konflikt zwischen den installierten Paketen und den in der Konfiguration aus der Vorlage konfigurierten Paketen.
Insbesondere dieser Teil:
<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>
Wenn ich dies ändere, um Version 5 zu verwenden, erhalte ich die Fehlermeldung, dass die Assembly (v5) nicht gefunden werden konnte usw.
Mir gehen die Ideen zur Lösung dieses Konflikts aus.
Hier sind die Konfigurationsabschnitte aus meiner SPA-Datei 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>
Wenn ich die Version auf 5 ändere, wird der folgende Fehler angezeigt:
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
Ich arbeite mit VS 2013 Pro Update 2. Das hat bei mir funktioniert:
Übrigens müssen an den Konfigurationsdateien keine Änderungen vorgenommen werden, und eine einfache Bereinigungs- und Neuerstellungslösung funktioniert nicht.
Haben Sie versucht, Ihre Lösung zu bereinigen und die temporären ASP.NET-Dateien unter zu löschen?
C:\WINDOWS\Microsoft.NET\Framework\v4.xxxx\Temporäre ASP.NET-Dateien
und umbauen?
Ich arbeite an VS 2015 und behebe dieses Problem.
Sie müssen Ihre Views/Web.Config-Datei überprüfen. Wenn die Konfigurationsdatei nicht vorhanden ist, können Sie ein anderes Projekt kopieren. Nachdem Sie den Namespace auf ändern müssen
----- ** Views/Web.Config ** ---------
<namespaces>
<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="YourProjectName" />
</namespaces>
----- ** Views/Web.Config ** ---------
wenn Sie eine Konfigurationsdatei haben, überprüfen Sie einfach den Namespace-Namen.
Ich habe gerade Update 2 für Visual Studio 2013 installiert und mein Problem ist verschwunden.