Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when pipeline in empty namespace #191

Closed
pascalberger opened this issue Jun 14, 2021 · 3 comments
Closed

Error when pipeline in empty namespace #191

pascalberger opened this issue Jun 14, 2021 · 3 comments
Labels
⚠️ Bug Something isn't working as expected

Comments

@pascalberger
Copy link
Contributor

I get an exception in Content/PostProcess pipeline:

[DBUG] Content/PostProcess » RenderContentPostProcessTemplates » ExecuteIf » ExecuteIf » ExecuteIf » ExecuteConfig » RenderRazor » Creating new RazorCompiler for null base page type
[DBUG] Content/PostProcess » RenderContentPostProcessTemplates » ExecuteIf » ExecuteIf » ExecuteIf » ExecuteConfig » RenderRazor » Compiling /index.md
[ERRO] Content/PostProcess » RenderContentPostProcessTemplates » ExecuteIf » ExecuteIf » ExecuteIf » ExecuteConfig » RenderRazor » [C:/git/swissgrc/doc.main/docs/input/index.md => index.html] Value cannot be null. (Parameter 'value')
[DBUG] Exception while executing pipeline Content/PostProcess: System.ArgumentNullException: Value cannot be null. (Parameter 'value')
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeWriter.Write(String value)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeWriterExtensions.WriteUsing(CodeWriter writer, String name, Boolean endLine)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeWriterExtensions.WriteUsing(CodeWriter writer, String name)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.RuntimeNodeWriter.WriteUsingDirective(CodeRenderingContext context, UsingDirectiveIntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.Visitor.VisitUsingDirective(UsingDirectiveIntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.Intermediate.UsingDirectiveIntermediateNode.Accept(IntermediateNodeVisitor visitor)
   at Microsoft.AspNetCore.Razor.Language.Intermediate.IntermediateNodeVisitor.Visit(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultCodeRenderingContext.RenderChildren(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.Visitor.VisitDefault(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.Visitor.VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.Intermediate.NamespaceDeclarationIntermediateNode.Accept(IntermediateNodeVisitor visitor)
   at Microsoft.AspNetCore.Razor.Language.Intermediate.IntermediateNodeVisitor.Visit(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultCodeRenderingContext.RenderChildren(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.Visitor.VisitDefault(IntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.Visitor.VisitDocument(DocumentIntermediateNode node)
   at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.WriteDocument(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase.ExecuteCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.ProcessCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Process(RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.GetCompilation(RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.<>c__DisplayClass11_0.<CompilePage>b__0(CompilerCacheKey _)
   at Statiq.Common.ConcurrentCache`2.<>c__DisplayClass2_1.<GetOrAdd>b__1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Statiq.Common.ConcurrentCache`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Statiq.Razor.CachingCompiler.GetOrAddCachedCompilation(CompilerCacheKey cacheKey, Func`2 valueFactory)
   at Statiq.Razor.RazorCompiler.CompilePage(RenderRequest request, Int32 contentCacheCode, RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.GetPageFromStreamAsync(IServiceProvider serviceProvider, RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()

Repro steps

  1. Create this csproj:
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Statiq.Web" Version="1.0.0-beta.31" />
      </ItemGroup>
    
    </Project>
    
  2. Create this program.cs
    using System.Threading.Tasks;
    using Statiq.App;
    using Statiq.Core;
    using Statiq.Web;
    
    namespace Docs
    {
        public class Program
        {
            public static async Task<int> Main(string[] args) =>
              await Bootstrapper
                .Factory
                .CreateWeb(args)
                .RunAsync();
        }
    }
    
    public class SearchIndex : Pipeline
    {
    }
    
  3. Add an empty input\index.md

Workaround

Move pipeline into namespace:

    using System.Threading.Tasks;
    using Statiq.App;
    using Statiq.Core;
    using Statiq.Web;

    namespace Docs
    {
        public class Program
        {
            public static async Task<int> Main(string[] args) =>
              await Bootstrapper
                .Factory
                .CreateWeb(args)
                .RunAsync();
        }

        public class SearchIndex : Pipeline
        {
        }
    }
@daveaglick
Copy link
Member

Finally getting a chance to look into this bug - some observations:

  • It's only triggered when there's a Markdown file in the input folder - a test.txt file won't trigger the problem. That suggests it's at least partly related to the existing pipelines in Statiq Web.
  • The namespace of the empty pipeline doesn't seem to matter as long as it's in a namespace. The bug appears to be related to empty pipelines in an empty namespace.

@daveaglick daveaglick changed the title Error when pipeline in different namespace than bootstrapping code Error when pipeline in empty namespace Jun 21, 2021
@daveaglick daveaglick added the ⚠️ Bug Something isn't working as expected label Jun 21, 2021
@daveaglick
Copy link
Member

Actually, the Markdown thing makes sense because the exception is happening inside the Razor engine and only Markdown, HTML, and Razor files are processed by Razor (as defined in the Statiq Web pipelines).

Another data point is that the bug is happening for any class defined in the global namespace, not just pipelines. In the call stack I can see it's being triggered during namespace writing in the Razor engine when generating code.

So...pretty sure the issue is that the IExecutionContext.Namespaces collection is getting a null value for the global namespace. That collection is automatically populated based on reflecting every object in every reference at startup. I suspect that when a reflected object doesn't have a namespace (I.e. the global namespace), we just add the result of the namespace reflection (which is null) to the collection.

daveaglick added a commit that referenced this issue Jun 21, 2021
@daveaglick
Copy link
Member

Fixed, will go out with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ Bug Something isn't working as expected
Development

No branches or pull requests

2 participants