Skip to content

Error with Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation in PublishSingleFile publishing mode #54315

@sqlnew

Description

@sqlnew

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using runtime compilation:
1.Set the FolderProfile.pubxml config is:
RazorCompileOnBuild:false
RazorCompileOnPublish:false
PublishSingleFile:true
PublishReadyToRun:false
2.Use the RuntimeCompilation:
builder.Services.AddRazorPages().AddRazorPagesOptions().AddRazorRuntimeCompilation();

If the publishing mode is "PublishSingleFile" mode, an error will occur when accessing the razor page url. The specific error is as follows:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ArgumentException: The value cannot be an empty string. (Parameter 'path')
at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)
at System.IO.Strategies.FileStreamHelpers.ValidateArguments(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.File.OpenRead(String path)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.CreateMetadataReference(String path)
at System.Linq.Enumerable.SelectListIterator2.Fill(ReadOnlySpan1 source, Span1 destination, Func2 func)
at System.Linq.Enumerable.SelectListIterator2.ToList() at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.GetCompilationReferences() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.get_CompilationReferences()
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.LazyMetadataReferenceFeature.get_References()
at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.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 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.CompileAndEmit(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.OnCacheMiss(String normalizedPath)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageLoader.LoadAsyncCore(PageActionDescriptor actionDescriptor, EndpointMetadataCollection endpointMetadata)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageLoaderMatcherPolicy.ApplyAsyncAwaited(PageLoader pageLoader, CandidateSet candidates, Task`1 actionDescriptorTask, Int32 index)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatch|10_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)

Expected Behavior

After using the "PublishSingleFile" publishing mode to publish the asp.net core program, there should have been no access error to asp.net.

Steps To Reproduce

  1. Create a new asp.net core razor pages project
  2. Add Microsoft AspNetCore MVC Razor The RuntimeCompilation component
  3. Add and modify code Program.cs and builder Services AddRazorPages().AddRazorPagesOptions() AddRazorRuntimeCompilation();
  4. Modify the FolderProfile.pubXML file
    RazorCompileOnBuild:false
    RazorCompileOnPublish:false
    PublishSingleFile:true
    PublishReadyToRun:false
  5. Public program
  6. Access the asp.net core address. This error will appear.

Exceptions (if any)

No response

.NET Version

8.0

Anything else?

error

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions