Layout could not be located after publishing
A follow up issue has been encountered upon deployment of the default template project to Linux. Exception stack trace is as follows:
Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN9IVAHRNA9A", Request id "0HN9IVAHRNA9A:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: The layout view '_Layout' could not be located. The following locations were searched:
/Views/Home/_Layout.cshtml
/Views/Shared/_Layout.cshtml
at Microsoft.AspNetCore.Mvc.Razor.RazorView.GetLayoutPage(ViewContext context, String executingFilePath, String layoutPath)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
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()
--- End of stack trace from previous location ---
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()
--- End of stack trace from previous location ---
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 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
What works is to change the Layout.vazor.vb to a _Layout.cshtml
@VBAndCs I have also looked into this and found the issue is possibly in the VazorViewMapper.vb file, in the AddStatic method where instead of:
Dim key = IO.Path.Combine(ViewInfo.FixPath(view.Path), view.Name) + ".cshtml"
I suggest using:
Dim key As String = ViewInfo.FixPath(Path.Combine(view.Path, view.Name)) + ".cshtml"
The cause of this issue is due to inconsistent path separators i.e.: Views\Shared/_Layout.cshtml. Dotnet on Linux combines the path with its path separator / unlike Windows which is \.
This requires to fix the FixPath itself 🙂 Public Shared Function FixPath(path As String) As String Return path.Replace(""c, "/"c).Trim("/"c) End Function
I advice you to include the Vazor source code directly in your project, make all the changes, and tell us with the result, so I can make a final release at once.
From: mmkathurima @.> Sent: Monday, January 20, 2025 7:35 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Mention @.> Subject: Re: [VBAndCs/Vazor] Layout could not be located after publishing (Issue #22)
@VBAndCshttps://github.com/VBAndCs I have also looked into this and found the issue is possibly in the VazorViewMapper.vb file, in the AddStatic method where instead of:
Dim key = IO.Path.Combine(ViewInfo.FixPath(view.Path), view.Name) + ".cshtml"
I suggest using:
Dim key As String = ViewInfo.FixPath(Path.Combine(view.Path, view.Name)) + ".cshtml"
The cause of this issue is due to inconsistent path separators i.e.: Views\Shared/_Layout.cshtml. Dotnet on Linux combines the path with its path separator / unlike Windows which is .
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2603126128, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVS3GCGUQUPY3IBS5732LVFY3AVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBTGEZDMMJSHA. You are receiving this because you were mentioned.Message ID: @.***>
I advice you to include the Vazor source code directly in your project, make all the changes, and tell us with the result, so I can make a final release at once.
I don't think I have understood this.
The issue lies in the path separators across different OSes not really in the FixPath method.
The FixPath method uses the "" separators which doesn't work on Linux. The "/" separator works on both Windows and Linux.
From: mmkathurima @.> Sent: Monday, January 20, 2025 8:39 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Mention @.> Subject: Re: [VBAndCs/Vazor] Layout could not be located after publishing (Issue #22)
I advice you to include the Vazor source code directly in your project, make all the changes, and tell us with the result, so I can make a final release at once.
I don't think I have understood this.
The issue lies in the path separators across different OSes not really in the FixPath method.
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2603200044, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVSWPAWGO22ZAFPRRP32LVNJ5AVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBTGIYDAMBUGQ. You are receiving this because you were mentioned.Message ID: @.***>
It's actually the opposite. / doesn't work on Windows and Linux but \ does. This means that instead of Views\Shared/_Layout.cshtml, it should have been Views\Shared\_Layout.cshtml.
Note that Windows supports either the forward slash (which is returned by the AltDirectorySeparatorCharhttps://learn.microsoft.com/en-us/dotnet/api/system.io.path.altdirectoryseparatorchar?view=net-9.0#system-io-path-altdirectoryseparatorchar field) or the backslash (which is returned by the DirectorySeparatorCharhttps://learn.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-9.0#system-io-path-directoryseparatorchar field) as path separator characters, while Unix-based systems support only the forward slash.
https://learn.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-9.0
From: mmkathurima @.> Sent: Monday, January 20, 2025 8:58 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Mention @.> Subject: Re: [VBAndCs/Vazor] Layout could not be located after publishing (Issue #22)
It's actually the opposite. / doesn't work on Windows and Linux but \ does. This means that instead of Views\Shared/_Layout.cshtml, it should have been Views\Shared_Layout.cshtml.
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2603220315, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVTXQA7CERNG5L2NQFL2LVPP3AVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBTGIZDAMZRGU. You are receiving this because you were mentioned.Message ID: @.***>
Did you manage to fix this?
Remove the Vazor NuGet from your project, and add the Vazor project itself (the source code) to thee solution, and make your project reference it directly. Make all changes that make you app run on Linux, then tell me about them at the end so I can modify update the nuget and the extension at once.
From: mmkathurima @.> Sent: Thursday, January 23, 2025 5:06 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Mention @.> Subject: Re: [VBAndCs/Vazor] Layout could not be located after publishing (Issue #22)
Did you manage to fix this?
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2610439171, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVTCFW2CDO53JBXQV6T2MEOQPAVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJQGQZTSMJXGE. You are receiving this because you were mentioned.Message ID: @.***>
How I was able to spot the issue and offer solutions was tinkering with the clones of your Vazor and ZML projects, building a .dll then adding it as a project reference instead of attaching the source code directly to my project.
- To fix this issue (#22): look at
VazorViewMapper.vbfile, in theAddStaticmethod where instead of:
Dim key = IO.Path.Combine(ViewInfo.FixPath(view.Path), view.Name) + ".cshtml"
I suggest using:
Dim key As String = ViewInfo.FixPath(Path.Combine(view.Path, view.Name)) + ".cshtml"
- To fix the #23 issue, find the
ZMLExtentions.vbfile of the ZML project at the line:
Public Const Ln = vbCrLf
I suggest changing it to the below, for the sake of compatibility across operating systems:
Public ReadOnly Ln As String = Environment.NewLine
SO FAR, I believe these are the major issues that I have been facing when trying to deploy the published project on Linux.
Remove the Vazor NuGet from your project, and add the Vazor project itself (the source code) to thee solution, and make your project reference it directly. Make all changes that make you app run on Linux, then tell me about them at the end so I can modify update the nuget and the extension at once. …
Looks like I may not have understood this. @InteXX care to assist?
@mmkathurima
@VBAndCs is referring to the process of removing the NuGet package from your project and referencing the source code directly from your project, just as we do every day in a solution with multiple projects.
You can git clone the source code to a location of your choosing on your system, add the .vbproj to the solution, and then reference that .vbproj from your main project.
Effect the changes that enable your code to work, and then post them in summary to this thread.
But even better ... learn how to do a pull request, so as to relieve some of @VBAndCs' burden. It's a way of saying 'thank you' for all the hard work he did that he's giving you for free.
It's all in the documentation. RTFM. Your free ChatGPT account can help you too.
Raising of pull requests is done in both Vazor and ZML repositories.
Hello @VBAndCs, it's been a while. Any progress?
Sorry, I am very busy updating Small Visual Basic: https://marketplace.visualstudio.com/items?itemName=ModernVBNET.sVBInstaller and using it to create Sahla, a very small Basic localized (Arabized) language that I encourage everyone to translate its tokens (defined at the start of the global.sb file) to his native language: https://marketplace.visualstudio.com/items?itemName=ModernVBNET.Sahla I will come back to this soon.
From: mmkathurima @.> Sent: Friday, March 28, 2025 5:27 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Mention @.> Subject: Re: [VBAndCs/Vazor] Layout could not be located after publishing (Issue #22)
Hello @VBAndCshttps://github.com/VBAndCs, it's been a while. Any progress?
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2761995083, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVRFZVSO3TBQVYAU77D2WWBAFAVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRRHE4TKMBYGM. You are receiving this because you were mentioned.Message ID: @.***>
[mmkathurima]mmkathurima left a comment (VBAndCs/Vazor#22)https://github.com/VBAndCs/Vazor/issues/22#issuecomment-2761995083
Hello @VBAndCshttps://github.com/VBAndCs, it's been a while. Any progress?
— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/22#issuecomment-2761995083, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVRFZVSO3TBQVYAU77D2WWBAFAVCNFSM6AAAAABVA5U7F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRRHE4TKMBYGM. You are receiving this because you were mentioned.Message ID: @.***>