dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.15k stars 9.92k forks source link

support single file embedded assemblies #45504

Open kasperk81 opened 1 year ago

kasperk81 commented 1 year ago

runtime compilation in .net 6 app published as a single file (<PublishSingleFile>true</PublishSingleFile>) works only with extraction to filesystem (<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>).

without extraction, it throws:

      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.SelectListIterator`2.ToList()
         at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.GetCompilationReferences()
         at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 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 ---

https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#api-incompatibility

if file-on-disk requirement is the only thing limiting user to access razor runtime compilation in PublishSingleFile apps, please consider adding support of in-memory assemblies without going through file i/o.

aside: in .net 7, this problem becomes real with <PublishAot>true</PublishAot>. there is no workaround as IncludeAllContentForSelfExtract because nativeaot does not use apphost.

chsienki commented 1 year ago

Moving to aspnetcore. In general it feels like these are two incompatible asks: to be ahead of time compiled, but also to do runtime compilation. Agree that the single file story could be improved though.

kasperk81 commented 1 year ago

In general it feels like these are two incompatible asks: to be ahead of time compiled, but also to do runtime compilation.

they are not. aot supports subset of reflection apis. if compilation code is restricted to just use those apis (and other apis on the "aot supported" surface) then it will be compatible with nativeaot. reading assemblies from memory map (bundle) is a plus for both singlfile and nativeaot.

yaobo-lab commented 1 year ago

i had the same problem. did you solve it?

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

yaobo-lab commented 9 months ago

i use.net 8, The problem still exists.

kasperk81 commented 7 months ago

@dotnet-policy-service this isn't a pr, this is an issue..

martincostello commented 7 months ago

53859

sqlnew commented 5 months ago

In the .net 8, The problem still exists. When using the Microsoft AspNetCore MVC Razor The RuntimeCompilation component to publish the asp.net core razor page project as a single file project and calling the dynamic compilation time AddRazorRuntimeCompilation, the same error occurs

Detailed problem description in this place https://github.com/dotnet/aspnetcore/issues/54315