Skip to content

Embedded views doesn't works after updating to .net core 3 #14374

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

Closed
geotinc opened this issue Sep 24, 2019 · 15 comments
Closed

Embedded views doesn't works after updating to .net core 3 #14374

geotinc opened this issue Sep 24, 2019 · 15 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@geotinc
Copy link

geotinc commented Sep 24, 2019

In other to migrate from asp.net core 2.2 to asp.net core 3
I change the code for loading external views as the following :

services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
            {
                options.FileProviders.Add(embeddedFileProvider);
            });

When running the project, I have the following error :
InvalidOperationException: The view 'Login' was not found. The following locations were searched: /Views/Account/Login.cshtml /Views/Shared/Login.cshtml /Pages/Shared/Login.cshtml

@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Sep 24, 2019
@javiercn
Copy link
Member

@geotinc Thanks for contacting us.

Could you provide a link to a github repo with a small repro project and detailed repro steps so that we can investigate?

@pranavkm any idea?

@geotinc
Copy link
Author

geotinc commented Sep 24, 2019

@javiercn I have push a sample here : https://github.com/geotinc/AspNetCore

Try to access /Test/Index => View not found

Thanks for helping

@geotinc
Copy link
Author

geotinc commented Sep 24, 2019

Thanks adding AddRazorRuntimeCompilation() works in my sample but in my real app I have the following error, any aidea ?

image

Thanks

@taori
Copy link
Contributor

taori commented Sep 24, 2019

#14359 has similar issues with a sample that are not fixed by just AddRazorRuntimeCompilation() - perhaps this issue is not dependent on it being embedded views.

@taori
Copy link
Contributor

taori commented Sep 24, 2019

@geotinc Have you tried adding your class library as a razor class library instead of making it a netcore app?

@geotinc
Copy link
Author

geotinc commented Sep 24, 2019

@taori Yes, I try without success

@fpanaccia
Copy link

fpanaccia commented Sep 25, 2019

Hi, i have a library that transforms views to pdf, with the views in the fileprovider i have the same exception "Cannot find reference assembly 'Microsoft.AspNetCore.Antiforgery.dll'", when using the "Physical" views i dont have the issue. I have tried some debugging, but the farthest i can go without breaking was here
namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
internal class DefaultRazorPageFactoryProvider : IRazorPageFactoryProvider
public RazorPageFactoryResult CreateFactory(string relativePath)
line 44 var viewDescriptor = compileTask.GetAwaiter().GetResult();

The code is in this repo

https://github.com/fpanaccia/Wkhtmltopdf.NetCore.Example.git

And the branch

feature/3.0

@javiercn
Copy link
Member

@geotinc Seems like your project is not correctly setup.

Id recommend you follow the guidance from https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio

Is there any specific reason why you are trying to embed the pages in the assembly directly?

@javiercn
Copy link
Member

@geotinc Our recommendation is that you use Razor Class Libraries instead of plain class libraries for razor, as they provide more features and a better experience.

If there's an scenario that you can't achieve with Razor Class Libraries feel free to open a new issue describing the requirement.

I'm closing this issue as there's nothing else for us to do here.

@fpanaccia
Copy link

@javiercn how would you solve my problem? #14374 (comment)

I don't have any views in the library, but i need to process them dynamically

@javiercn
Copy link
Member

@fpanaccia Could you please open a separate issue so that we can track and prioritize your issue appropriately?

Could you also include more details on what you are trying to accomplish and how?
It's unclear from the description in your comment and the repro project you provided.

@geotinc
Copy link
Author

geotinc commented Sep 25, 2019

@javiercn I just dont now that there is other way to do that.
I will try again migrating my referenced dll to razor class library
thanks for helping

@geotinc
Copy link
Author

geotinc commented Sep 25, 2019

@javiercn I confirm that everything seems to work well after migrating to RCL.
Thanks all for your help

@alextof
Copy link

alextof commented Oct 15, 2019

@mkArtakMSFT , @javiercn, @geotinc I do also have some issues with the Embedded Views. Here I provide a solution with .NET Core 2.2 working and .NET Core 3.0 not working.

Could someone give me a hand please? I'm struggling to make my RazorViewToStringRenderer to find the View from the Embedded Razor Class Library.

Source Code: https://dev.azure.com/okyselov/_git/ConsoleAppEmbeddedRazorViews

@pranavkm
Copy link
Contributor

@alextof could you please file a separate issue?

@dotnet dotnet locked as resolved and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

7 participants