【问题标题】:Error RZ3007: Targeted tag name cannot be null or whitespace错误 RZ3007:目标标记名称不能为空或空格
【发布时间】:2018-01-29 16:08:18
【问题描述】:

升级到 .NET Core 2.0 后,我的 1.1 Web 应用程序无法运行。我收到如下所示的错误消息。检查输出后,我发现对 RZ3007 错误的引用,我认为该错误与 Razor 编译器有关。视图未编译。

首页/Index.cshtml:

@model LayoutViewModel
<div></div>

视图/共享/_Layout.cshtml

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - GLCoderConfiguration</title>

    <environment names="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css?" />
    </environment>
    <environment names="Staging,Production">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css?" asp-append-version="true" />

   </environment>
</head>
<body>
    <nav class="navbar navbar-default navbar-form " >

        <div class="navbar-header" style="margin-top:10px;margin-bottom:15px;">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">SCM - NCMain</a>
        </div>


        <div class="collapse navbar-collapse vcenter" id="bs-example-navbar-collapse-1" style="margin-top:10px;margin-bottom:0px;">

      </div>
    </nav>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; 2017 - England Logisitics - SCM</p>
        </footer>
    </div>

    <environment names="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
        </script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>


    </environment>

    @RenderSection("Scripts", required: false)
  </body>
</html>

我有几个视图组件(LoginStatus 和 MenuItems),但删除了它们以尝试使其正常工作。

运行输出:

    Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
(0,0): Error RZ3007: Targeted tag name cannot be null or whitespace.
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry(String normalizedPath)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeResultAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResultFilterAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

.CSProj

    <Project Sdk="Microsoft.NET.Sdk.Web">

      <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
        <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
        <MvcCompileViews>true</MvcCompileViews>
        <PreserveCompilationContext>true</PreserveCompilationContext>
        <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
        <StartupObject>GLCoderConfiguration.Program</StartupObject>
      </PropertyGroup>

      <ItemGroup>
        <PackageReference Include="FluentValidation" Version="7.1.1" />
        <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
        <PackageReference Include="Microsoft.NETCore.Platforms" Version="2.0.0" />
        <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
        <PackageReference Include="NETStandard.Library" Version="2.0.0" />
        <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
      </ItemGroup>

      <ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>
      <ItemGroup>
        <ProjectReference Include="..\..\SCMEnumerations\SCMEnumerations.csproj" />
        <ProjectReference Include="..\..\TMainModel\TMainModel.csproj" />
        <ProjectReference Include="..\..\ViewHelperFunctions\ViewExtensions.csproj" />
      </ItemGroup>

    </Project>

【问题讨论】:

    标签: razor asp.net-core runtime-error asp.net-core-2.0


    【解决方案1】:

    这个方法对我有用:

    • 删除objbin 文件夹
    • 运行dotnet restore
    • 运行dotnet build

    【讨论】:

    • 这对我也有用。 dotnet --version 2.1.200
    【解决方案2】:

    我最终查看了Microsoft. 中详细介绍的步骤,然后完全卸载了 Visual Studio 并重新安装。然后我创建了一个新的 Web 项目,将其设置为 2.0,然后从非工作解决方案中复制文件,事情开始自动工作。我仍然需要确保正确配置了身份验证,但事情已经开始顺理成章了。

    【讨论】:

    • 嗨@dmcquay,我也遇到了这个问题,还不得不从头开始重新创建我的项目来解决这个问题,我们不应该这样做......我最近才发现再次出现问题,几乎没有理由这样做......查看我的 git repo 并比较上次成功构建之间的更改!您是否了解过有关此错误的任何其他信息?在我的标准 dot net core 开发环境中,我花了太多时间来处理这些类型的错误。
    【解决方案3】:

    尝试将environment names替换为environment includelike。

    <environment include="Staging,Production">
      <strong>HostingEnvironment.EnvironmentName is Staging or Production</strong>
    </environment>
    

    根据documentation

    include 属性(在 ASP.NET Core 2.0 中)具有与 names 属性类似的行为 ASP.NET Core 1.0。

    更新: 尝试使用 .csproj 之类的包自己迁移我的一些项目(从 1.1 到 2.0),以便重现您的错误,但不幸的是没有运气。不确定,但可能是预编译造成的。

    我有时有CompilationFailedException,但它就像CS0246 并显示导致问题的行。但是您的 RZ3007(0,0) 看起来像 Razor 本身不知何故坏了。可能你应该在 Github 上打开新问题。
    不确定是否有帮助,但请尝试安装Microsoft.AspNetCore.Razor.Language NuGet 包,因为如果您read this discussion 关于 Razor 更改,似乎需要它。

    如果您现在不使用 Visual Studio 2017,请尝试将其更新到 15.3 版。 另外,请确保 SDK 已更新至 2.0 版

    【讨论】:

    • 试过了。没有骰子。根据文档,我认为名称属性仍然有效。
    • @dmcquay 我明白了,奇怪。那么请用您的*.csproj 文件的内容更新您的问题。
    【解决方案4】:

    *.csproj 中删除下面的行为我修复了它

    &lt;PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" /&gt;

    我在阅读 upgrade documents 中的 Review your Ra​​zor View Compilation setting 部分后添加了它。事实证明,添加它不是一个好主意!

    【讨论】:

      【解决方案5】:

      在 netcore-2.0 之前的版本中的 Startuppublic void ConfigureServices(IServiceCollection services) 方法中,需要一种解决方法:

      services.AddMvc()
              .AddApplicationPart(typeof(SomeController).GetTypeInfo().Assembly)
              .AddRazorOptions(options =>
              {
                  // By docs this should work out of the box, but due to a bug this workaround is needed currently:
                  foreach (var name in typeof(Program).GetTypeInfo().Assembly.GetReferencedAssemblies())
                          options.AdditionalCompilationReferences.Add(MetadataReference.CreateFromFile(Assembly.Load(name).Location));
              })
              ;
      

      但现在不是了。以下内容就足够了:

      services.AddMvc()
              .AddApplicationPart(typeof(SomeController).GetTypeInfo().Assembly);
      

      保留解决方法会导致上述 RZ3007 错误。

      【讨论】:

      • 这个答案中的 TowerController 来自哪里?
      • 对不起,我把措辞改成了“SomeController”,意思是任何控制器。
      【解决方案6】:

      在我的情况下,在.csproj 中禁用此 Razor 设置有效:

      <PropertyGroup>   
      <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
      ...
      

      【讨论】:

        【解决方案7】:

        在我的 *csproj 文件中有这个:

          <ItemGroup>
           <Reference Include="System.Private.Xml">
             <HintPath>C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Private.Xml.dll</HintPath>
           </Reference>
         </ItemGroup>
        

        不知道它来自哪里,但删除它解决了问题。

        【讨论】:

          【解决方案8】:

          从 Visual Studio 2019 发布时,我检查了 Remove additional files at destination 发布选项,这解决了这个问题。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多