The Wayback Machine - https://web.archive.org/web/20220205173656/https://github.com/dotnet/aspnetcore/issues/40012
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

Razor runtime compilation doesnt work second time with virtual file path providers? #40012

Open
1 task done
aloksharma1 opened this issue Feb 5, 2022 · 0 comments
Open
1 task done

Comments

@aloksharma1
Copy link

@aloksharma1 aloksharma1 commented Feb 5, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

hello,
when i use AddRazorRuntimeCompilation method with custom view providers from database or other virtual paths, the views are refreshed when files are first loaded. but after that changes are not respected even if IFIleProvider Stream method is called the old copy gets picked every time. I tested this behavior with using view pages/view component/partial/render partial or tag helpers with same result even when the compiler is recreating file, its serving from old cached entry.
To trace the issue i copied netcore repo and traced the debugger hitting the required methods correctly, for info :
for a custom IFileProvider -

  1. IChangeToken sends true on page change in database
  2. IFileInfo _exists method is set true, and stream is sent with new content using CreateReadStream
  3. RuntimeViewCompiler class hits and check for changes correctly & even a new assembly is generated on CompileAndEmit method.
  4. but even after successful execution of CompileAndEmit methods this part i am getting the old page:
            var loader = new RazorCompiledItemLoader();
            var item = loader.LoadItems(assembly).SingleOrDefault();
            var compilerDescriptor = new CompiledViewDescriptor(item);
            return compilerDescriptor;

here old page is served, no matter how many refresh/browser changes/cache disabled or whatever i tried, its always the same.

Expected Behavior

compilation must take effect whenever file is modified without restarting the application.
getting same behavior on net 5.0.13 and net 6.0.1

Steps To Reproduce

create a virtual file provider to serve razor from database or other alternate sources, for example explained here mikes dotnetting

var mvcBuilder = services.AddMvc();
var PhysicalFileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory());
var dBPageProvider = new DBPageProvider(serviceCollection.BuildServiceProvider());
var _CompositeFileProvider = new CompositeFileProvider(dBPageProvider, PhysicalFileProvider);
mvcBuilder.AddRazorRuntimeCompilation(options =>
            {
                options.FileProviders.Clear();
                options.FileProviders.Add(dBPageProvider);
            }); 

Exceptions (if any)

none

.NET Version

5.0.404 & 6.0.101

Anything else?

5.0.13 and 6.0.1 both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant