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

"Blank Recipe" theme and error at first running: "InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'OrchardCore.Diagnostics.ViewModels.HttpErrorShapeViewModel', but this ViewDataDictionary instance requires a model item of type 'WebApp.Models.ErrorViewModel'" #15267

Open
MarGraz opened this issue Feb 7, 2024 · 7 comments

Comments

@MarGraz
Copy link
Contributor

MarGraz commented Feb 7, 2024

Describe the bug

I followed the official documentation to create a new Orchard Core Web App and installed the OrchardCore.Application.Cms.Targets and OrchardCore.Application.Targets NuGet packages as suggested in the second GIF image.
After configuring the Web App to use a SQL Server on localhost and starting the app, I encountered an error on the front end:

An unhandled exception occurred while processing the request. InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'OrchardCore.Diagnostics.ViewModels.HttpErrorShapeViewModel', but this ViewDataDictionary instance requires a model item of type 'WebApp.Models.ErrorViewModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value)

Despite using a blank recipe, which I thought might naturally lead to front-end errors, I followed the official guide to create my own theme (using the Code Generation Templates) and added a Layout.cshtml with only an "Hello world" text. I also updated the .csproj file to use the Microsoft.NET.Sdk.Razor SDK, but the error persisted.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new blank ASP.NET Core Web Application (.NET 8) in VS 2022 v. 17.8.6;
  2. Install OrchardCore.Application.Cms.Targets v. 1.8.2 and OrchardCore.Application.Targets v. 1.8.2 from the stable NuGet feed, as shown in the second GIF image;
  3. Run the Web App with CTRL + F5 and configure it to use a localhost SQL Server;
  4. Attempt to access the frontend to encounter the described error.

Expected behavior

Using a "Blank Recipe" I expected not to see a template, but also not to encounter an exception. Ideally, a simple text page should appear, guiding the user to consult the documentation for creating a custom theme and locating the "Admin" panel.

Endpoint

Name Value
Display Name OrchardCore.Diagnostics.Controllers.DiagnosticsController.Error (OrchardCore.Diagnostics)
Route Pattern Error/{status?}
Route Order 71

Route Values

Variable Value
action Error
area OrchardCore.Diagnostics
controller Diagnostics
status 404

Exception details

System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'OrchardCore.Diagnostics.ViewModels.HttpErrorShapeViewModel', but this ViewDataDictionary instance requires a model item of type 'WebApp.Models.ErrorViewModel'.
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(Object value)
   at lambda_method93(Closure, ViewDataDictionary)
   at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.Activate(Object page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, Boolean retry)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at OrchardCore.Liquid.ScriptsMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|10_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
   at OrchardCore.Diagnostics.DiagnosticsStartupFilter.<>c__DisplayClass3_0.<<Configure>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.<>c__DisplayClass7_0.<<CreateHandler>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at OrchardCore.ContentPreview.PreviewStartupFilter.<>c.<<Configure>b__0_1>d.MoveNext()
--- End of stack trace from previous location ---
   at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext)
   at OrchardCore.Modules.ModularTenantContainerMiddleware.<>c__DisplayClass4_0.<<Invoke>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Screenshots

image

@MarGraz
Copy link
Contributor Author

MarGraz commented Feb 7, 2024

I noticed that there is a discrepancy in the official documentation. The second GIF image recommends using the NuGet packages OrchardCore.Application.Cms.Targets and OrchardCore.Application.Targets. However, another section of the documentation here advises using OrchardCore.Application.Cms.Targets and OrchardCore.Application.Cms.Core.Targets.

After updating my WebApp to reference OrchardCore.Application.Cms.Targets and OrchardCore.Application.Cms.Core.Targets, both version 1.8.2, I still encounter the same error, with or without my theme project referenced or not.

@MarGraz
Copy link
Contributor Author

MarGraz commented Feb 7, 2024

The issue starts with creating a new blank "ASP.NET Core Web Application" in VS 2022 using the manual method. This process, unlike the automated template, results in Visual Studio automatically adding Controllers and Views folders with files, that subsequently cause errors in Orchard Core, specifically because of the Error.cshtml view model. Excluding the Controllers and Views folders from the project fix this issue.

I noticed that the official documentation does not mention to remove Controllers and Views folders when starting a project with the manual method, right? 🤔

  1. Could you specify where in the documentation the "manual method" is mentioned? I would like to add a note about removing the Controllers, Views and Models folders from the Web App, assuming this is the correct approach 😊
  2. Regarding my previous comment, can you confirm the discrepancy between the GIF image and the documentation? If confirmed, I think it should be fixed

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Feb 7, 2024

@MarGraz
is there a controller in your web project that handle errors? You may have Error.cshtml in the shared folder which should be removed. Also, if you have a controller in your webapp that handles errors, delete it

@MarGraz
Copy link
Contributor Author

MarGraz commented Feb 7, 2024

@MikeAlhayek yes, thank you. I solved as I explained here. What do you think about the two questions I asked?

@MikeAlhayek
Copy link
Member

@MarGraz sorry I did not see you follow up comments. Glad you fixed the issues.

Yes feel free to submit a PR to modify the documentation to mention removing the views and controller if existing.

@MarGraz
Copy link
Contributor Author

MarGraz commented Feb 7, 2024

@MikeAlhayek ok, I have just two questions:

  • Regarding this comment I posted, which library is the correct one to be used?
  • Where in the documentation is the "manual method" mentioned? Is it only on this page?

Thank you

@MikeAlhayek
Copy link
Member

Regarding #15267 (comment) I posted, which library is the correct one to be used?
OrchardCore.Application.Cms.Core.Targets or OrchardCore.Application.Cms.Targets can be used. It depends on the scenario you want to achieve. I would suggest to use OrchardCore.Application.Cms.Targets and change it if needed

Where in the documentation is the "manual method" mentioned? Is it only on this page?

In this section https://docs.orchardcore.net/en/main/docs/getting-started/templates/#from-visual-studio-manual-way we should add a section to mention removing the views and controllers.

MarGraz added a commit to MarGraz/OrchardCore that referenced this issue Feb 9, 2024
As discussed in this issue OrchardCMS#15267 I added the NuGet packages names to the guide, and the instruction to delete "Models", "Views" and "Controllers" folder, automatically added by the Visual Studio scaffolding.
@Piedone Piedone added this to the 2.x milestone May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants