Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

views cannot be served #4189

Closed
ciel opened this issue Feb 29, 2016 · 24 comments
Closed

views cannot be served #4189

ciel opened this issue Feb 29, 2016 · 24 comments
Labels

Comments

@ciel
Copy link

ciel commented Feb 29, 2016

Using the current repository, run the MvcSandbox project verbatim with no changes using the following commands;

dotnet restore
dotnet build
dotnet run

You are served an error that views cannot be found, but it clearly lists the correct directories.

An unhandled exception occurred while processing the request.

InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)

using dotnet version 1.0.0-beta-001540 and compiled against coreclr-1.0.0-rc2-16551x64 on Windows 10x64.

@ciel
Copy link
Author

ciel commented Feb 29, 2016

Here's the full stack trace;

System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
   at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultAsync>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultFilterAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAllResultFiltersAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResourceFilterAsync>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.<InvokeActionAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

@pranavkm
Copy link
Contributor

You'd need to specify the applicationbase. Here's what my powershell command looks lke: dotnet run -- --applicationbase $PWD

@ciel
Copy link
Author

ciel commented Feb 29, 2016

I'm not sure I understand. I can't find this documented anywhere.

@ciel
Copy link
Author

ciel commented Feb 29, 2016

Okay, I think I understand now. Is there any way to put this setting in a
file?
On Feb 28, 2016 9:50 PM, "Pranav K" [email protected] wrote:

You'd need to specify the applicationbase. Here's what my powershell
command looks lke: dotnet run -- --applicationbase $PWD


Reply to this email directly or view it on GitHub
#4189 (comment).

@pranavkm
Copy link
Contributor

@ciel, there's a UseApplicationBasePath argument on IWebHostBuilder that you could use. Alternatively if your app is using a config file, you could add the applicationBase key to it.

@davidfowl
Copy link
Member

@ciel
Copy link
Author

ciel commented Mar 20, 2016

Was this changed yet again?

@davidfowl
Copy link
Member

@ciel the name of the property changed.

@JoseFMP
Copy link

JoseFMP commented Aug 10, 2017

So, how to set it now? August 2017 more than one year later this issue still there.

@davidfowl
Copy link
Member

@jose-cf how are you seeing the issue? What does your project look like and what command did you run

@JoseFMP
Copy link

JoseFMP commented Aug 14, 2017

To reproduce:

  • Create an ASP .NET project (tried several target frameworks, net461, net462, netcoreapp1.0, netcoreapp1.1, netcoreapp2.0 with same result).
  • Install Microsoft.AspNetCore.Mvc package (as well as it dependencies).
  • Create simple controller with hello world view.
  • Configure the server you want, several server tried to I do believe not server related... some of the ones I tried: Kerstell, IIS.
  • Run your app: tried different ways, through IIS, through a console launcher, using different dotnet sdk's... seems no difference.
  • Request your hello world controller/view: Can see with the debugger and log messages the controller is found. However when creating the view... it crashes:
System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
   at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultAsync>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultFilterAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAllResultFiltersAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResourceFilterAsync>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.<InvokeActionAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

I tried to add different locations. I also tried to hardcode the locations. Still no matter what I tried, never finds the views.
Tried with several versions of Microsoft.AspNetCore.* seems no difference. Setting the root/application base paths seems to not to fix the issue.
Also tried in different servers with Windows and Linux, still no difference, the views cannot be found.

@pranavkm
Copy link
Contributor

If you're using Asp.Net Core< v2.0, you need to ensure you have builder.UseContentRoot(Directory.GetCurrentDirectory()) in your Program.Main. I'd recommend using the Mvc template (dotnet new mvc) and let it wire up things for you rather installing the packages piecemeal.

@JoseFMP
Copy link

JoseFMP commented Aug 15, 2017

@pranavkm Sure.
I used the template, and also tried to do from an empty project, etc.
Sure as I said in my original message, I double check all the content root and base paths are properly set.
In addition I also tried to put hardcoded paths to the views just to check out if there is a problem with that.

But from all the permutations of workarounds and things I tried nothing works. I always get that exception. So really... to me does not look like a configuration problem but like a bug.

@danroth27
Copy link
Member

@jose-cf Could you please zip up your project that reproduces the issue and send it to us?

@JoseFMP
Copy link

JoseFMP commented Aug 18, 2017

Sure... Where can I send it?! That said... really no magic in the project ... really empty. Please tell me an address where to send it.

By the way... same behavior with .NET Core 2.0

@davidfowl
Copy link
Member

Github would be best

@JoseFMP
Copy link

JoseFMP commented Aug 21, 2017

I typed dotnet new mvc. I think it's easier if you type it. But still, I can put it in a repo if necessary.

Also tried dotnet new razor

@davidfowl
Copy link
Member

davidfowl commented Aug 21, 2017

dotnet new razor and dotent new mvc work on my machine. Can you provide a bit more information?

@JoseFMP
Copy link

JoseFMP commented Aug 21, 2017

@davidfowl I do believe it works in your machine. That does not really help me or anyone having this problem though ;)

So, as I stated already, when finding the view I get this exception:

System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
   at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultAsync>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResultFilterAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAllResultFiltersAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeResourceFilterAsync>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.<InvokeActionAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

I tried it in Win 10 (x64), Windows Server 2016, Ubuntu, with same result unfortunately.
I tried different target frameworks, including net461, netcoreapp1.1, netcoreapp2.0 (recently) with same result unfortunately.
I also tried to hardcode the locations of the views, no luck either.

Strange, but I am not the only one experiencing it... if you google this issue you will find plenty of people stuck in this bug.

@oldsand
Copy link

oldsand commented Aug 29, 2017

I have the same issue as well when I after I use the MapRoute inside the Startup.cs

  routes.MapRoute(
                    name: "pagination",
                    template: "Products/Page{page}",
                    defaults: new { controller = "Product", action = "List" });

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=List}/{id?}");
)

@pranavkm
Copy link
Contributor

@oldsand you're running in to a bug we introduced in 2.0. #6660 (comment) describes some workarounds.

@shlomishemesh1
Copy link

shlomishemesh1 commented Nov 18, 2017

LesingProject.zip

Hi, I have the same problem and I will be happy if someone can help me.
When I try to run the app in this location http://localhost:62657/admin/dashboard/index I got the same problem.

InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Dashboard/Index.cshtml /Views/Shared/Index.cshtml

Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
Microsoft.AspNetCore.Mvc.ViewResult+<ExecuteResultAsync>d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeResultAsync>d__19.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResultFilterAsync>d__24.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

@pranavkm
Copy link
Contributor

@shlomishemesh1 you're commenting on a closed \ resolved issue. Could you create a new work item?

@redbar0n
Copy link

redbar0n commented Mar 14, 2018

FWIW, In our case we received this error when accessing localhost:<port>/graphql even though the View/GraphQL/Index.cshtml was in the right place. We got the error because wwwroot/bundle.js and wwwroot/style.js was mistakenly not initially committed, since our .gitignore included wwwroot. Discovered it by inspecting the network traffic and seeing it was these files giving the 404 and not the Index.cshtml itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants