当前位置:   article > 正文

Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with...

.net6 useexceptionhandler an exception was thrown attempting to execute the

project.json 配置:

  1. {
  2. "version": "1.0.0-*",
  3. "compilationOptions": {
  4. "emitEntryPoint": true
  5. },
  6. "dependencies": {
  7. "Microsoft.AspNet.Diagnostics": "1.0.0-rc2-16303",
  8. "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc2-15994",
  9. "Microsoft.AspNet.Mvc": "6.0.0-rc2-16614",
  10. "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc2-16614",
  11. "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc2-16156",
  12. "Microsoft.AspNet.StaticFiles": "1.0.0-rc2-16036",
  13. "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc2-15994",
  14. "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc2-15905",
  15. "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-15905",
  16. "Microsoft.Extensions.Logging": "1.0.0-rc2-15907",
  17. "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-15907",
  18. "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-15907",
  19. "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-16142"
  20. },
  21. "commands": {
  22. "web": "Microsoft.AspNet.Server.Kestrel"
  23. },
  24. "frameworks": {
  25. "dnx451": { }
  26. },
  27. "exclude": [
  28. "wwwroot",
  29. "node_modules"
  30. ],
  31. "publishExclude": [
  32. "**.user",
  33. "**.vspscc"
  34. ],
  35. "scripts": {
  36. "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  37. }
  38. }

注意 dependencies 中的程序包都是 rc2 版本(截止目前的最新版本),这时候运行将会抱下面的异常:

  1. fail: Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware[0]
  2. An exception was thrown attempting to execute the error handler.
  3. System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.CompilationAbstractions.ILibraryExporter' while attempting to activate 'Microsoft.AspNet.Mvc.Razor.Compilation.RoslynCompilationService'.
  4. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
  5. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain)
  6. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain)
  7. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain)
  8. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
  9. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain)
  10. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain)
  11. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain)
  12. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
  13. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain)
  14. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain)
  15. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain)
  16. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
  17. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain)
  18. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain)
  19. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain)
  20. at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider)
  21. at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary`2 dictionary, TKey key, Func`3 valueFactory, TArg arg)
  22. at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
  23. at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
  24. at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
  25. at Microsoft.AspNet.Mvc.Razor.Internal.MvcRazorMvcViewOptionsSetup.ConfigureMvc(IServiceProvider serviceProvider, MvcViewOptions options)
  26. at Microsoft.AspNet.Mvc.Razor.Internal.MvcRazorMvcViewOptionsSetup.<>c__DisplayClass0_0.<.ctor>b__0(MvcViewOptions options)
  27. at Microsoft.Extensions.OptionsModel.ConfigureOptions`1.Configure(TOptions options)
  28. at Microsoft.Extensions.OptionsModel.OptionsManager`1.<>c.<get_Value>b__4_0(TOptions options, IConfigureOptions`1 setup)
  29. at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
  30. at Microsoft.Extensions.OptionsModel.OptionsManager`1.get_Value()
  31. at Microsoft.AspNet.Mvc.ViewEngines.CompositeViewEngine..ctor(IOptions`1 optionsAccessor)
  32. --- End of inner exception stack trace ---

解决方案:将 dnx 的版本升级到 rc2,命令行输入 dnvm upgrade -u,升级之后:

如果 VS 2015 调试运行,需要在 Web 属性中选择 dnx 的版本:

重新运行,又出现下面的异常:

  1. fail: Microsoft.AspNet.Server.Kestrel[13]
  2. An unhandled exception was thrown by the application.
  3. Microsoft.AspNet.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
  4. Error @ (38:1,14)(36) - [Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'. Error: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)] (1,14) Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'. Error: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
  5. at Microsoft.AspNet.Mvc.Razor.Compilation.CompilationResult.EnsureSuccessful()
  6. at Microsoft.AspNet.Mvc.Razor.Compilation.CompilerCache.CreateCacheEntry(String normalizedPath, Func`2 compile)
  7. at Microsoft.AspNet.Mvc.Razor.Compilation.CompilerCache.GetOrAdd(String relativePath, Func`2 compile)
  8. at Microsoft.AspNet.Mvc.Razor.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
  9. at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
  10. at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
  11. at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
  12. at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
  13. at Microsoft.AspNet.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
  14. at Microsoft.AspNet.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
  15. at Microsoft.AspNet.Mvc.ViewResult.<ExecuteResultAsync>d__24.MoveNext()
  16. --- End of stack trace from previous location where exception was thrown ---
  17. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  18. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  19. at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeResultAsync>d__45.MoveNext()
  20. --- End of stack trace from previous location where exception was thrown ---
  21. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  22. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  23. at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
  24. at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeResultFilterAsync>d__44.MoveNext()
  25. --- End of stack trace from previous location where exception was thrown ---
  26. at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAllResultFiltersAsync>d__43.MoveNext()
  27. --- End of stack trace from previous location where exception was thrown ---
  28. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  29. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  30. at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
  31. at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeResourceFilterAsync>d__38.MoveNext()
  32. --- End of stack trace from previous location where exception was thrown ---
  33. at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__33.MoveNext()
  34. --- End of stack trace from previous location where exception was thrown ---
  35. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  36. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  37. at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<InvokeActionAsync>d__8.MoveNext()
  38. --- End of stack trace from previous location where exception was thrown ---
  39. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  40. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  41. at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
  42. --- End of stack trace from previous location where exception was thrown ---
  43. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  44. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  45. at Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.<Invoke>d__4.MoveNext()
  46. --- End of stack trace from previous location where exception was thrown ---
  47. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  48. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  49. at Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
  50. --- End of stack trace from previous location where exception was thrown ---
  51. at Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
  52. --- End of stack trace from previous location where exception was thrown ---
  53. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  54. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  55. at Microsoft.AspNet.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
  56. --- End of stack trace from previous location where exception was thrown ---
  57. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  58. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  59. at Microsoft.AspNet.Hosting.Internal.HostingApplication.<ProcessRequestAsync>d__7.MoveNext()
  60. --- End of stack trace from previous location where exception was thrown ---
  61. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  62. at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  63. at Microsoft.AspNet.Server.Kestrel.Http.Frame`1.<RequestProcessingAsync>d__3.MoveNext()

解决方案:将 Views/_ViewImports.cshtml 中的 @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" 修改如下:

  1. @using WebApplication1
  2. @addTagHelper *, Microsoft.AspNet.Mvc.TagHelpers

修改之后,VS 2015 会提示错误,不用管它,dnx web 重新运行 OK。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/162930
推荐阅读
相关标签
  

闽ICP备14008679号