I ran into a strange problem in my project.
This problem occurs when I want to return a specific razor view inside a method. But the point is that this problem only happens when I have used tag helpers like asp-for, otherwise there is no problem.
Error Page screenshot
First you should update your Visual Studio's installation. You can't run the latest ASP.NET core apps with the older versions. It's explained here. Take a look at its The Visual Studio / .NET Core SDK support matrix to see what's the real problem.
Also follow this thread: https://stackoverflow.com/a/44723132/298573
Related
We are developing a rich REST Api using the very nice JsonApiDotNetCore library (5.0.1).
We have many dozens of APIs working just fine.
However, today I updated my VS 2022 to 17.3.0, and now when I try to run I get
the error JsonApiDotNetCore.Errors.InvalidConfigurationException with the message "Multiple controllers found for resource type ...
Running the same source on a non-updated VS2022 works just fine.
Any clues out there?
Thanks to the JsonApiDotNetCore dev team, especially bkoelman, he responded with a bunch of info on the github Issue Tracker In our case, we needed to have a scaffold controller, due to requirements in our app for attributes supporting security. We were also using the [Resource] attribute on our controller scaffold. The Resource tag was generating the full controllers therefore our scaffold was producing the error. I guess this is a known bug in the .Net Core 6 SDK. The fix was to remove the [Resource] attribute.
I don't know why I get this error every time in ASP.NET Core MVC 3.1. I have a view and it's in its place. I only get this error in areas.
InvalidOperationException: The view 'Dashboard' was not found. The following locations were searched:
/Areas/Admin/Views/Home/Dashboard.cshtml
/Areas/Admin/Views/Shared/Dashboard.cshtml
/Views/Shared/Dashboard.cshtml
Nine times out of ten, this error on a view is because you forgot to put the [Area("Admin")] attribute at the top of your area controller(s).
Note: As you noted in your answer, this should not include the suffix Area.
While your area views are, by convention, searched for in /Areas/{Area}/Views/, there’s no effort to implicitly determine that a controller is intended for an area. In other words, .NET is exclusively relying on the [Area()] attribute, independent of whether your controller(s) live in e.g. /Areas/{Area}/Controllers/. You’ll probably store them there anyway for organizational purposes, but .NET doesn’t care either way.
I had this problem recently (after upgrading a project from .NET 5.0 to .NET 6.0) and found when I built the project locally and then deployed manually everything worked but when building and deploying via Azure Devops it failed.
After much head scratching, it turned out to be that the build definition was still set to use Visual Studio 2019 when it should have been using Visual Studio 2022 (because it can build 6.0 projects).
I resolved this problem by changing the area name from "AdminArea" to "Admin"
I am trying to build a read only .net rest api using the following tutorial on Microsoft Docs-(https://learn.microsoft.com/en-us/aspnet/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api)
According to the tutorial when i add a controller the following error popup.
I have tried other solutions on stackoverflow like
Clearing ComponentModelCache
Also deleting .vs folder in solution
But nothing helped
Try changing your project to .NET Framework instead of .NET Core and make sure you are able to create a solution with .NET Framework. If the issue still persists please provide some additional log details of VisualStudio when creating with .NET Core
In many projects that I and others I have there is an Ambiguous reference error that pops up if i use an object that is apart of a different asp.net5 project. Funny enough it still compiles and works but there is no intellisense and my code is covered in red lines.
An example of this is I have a Tests project pointing to my MVC project. When i try to create a new instance of XController, it will show an error that it doesnt know which XController to use the DNX 4.5.1 or DNX 5.0. I am aware of what those are but it wont let me choose, even though I feel like I shouldnt. Again, it works, just frustrating.
The only way I can get this to work is if I choose only one framework for my MVC project. I dont like doing this because I want to know if dnxcore50 doesnt support something that I am writing in the MVC app. I tried only using one framework in the unit test project but that did not work.
I want to be clear that I do understand that asp.net 5 stuff is in beta and there are many bugs. I am wondering if this is a a bug or if I am just doing something wrong.
Update 1: It seems the problem only occurs if I have a new Asp.Net 5 Class library referencing a Asp.Net 5 Mvc project. Library to library works and mvc to library also works.
After spending some time talking to the guys involved with the Asp.net 5 development team, we've come to the conclusion that this was, in my case certainly, a ReSharper issue.
If you switch off ReSharper the errors disappear.
Thanks
Looks like the solution is to only use one framework when referencing an MVC Project from another project. Seems to be just a bug.
I'm trying to use a simple Default.aspx WebForm generated from a simple ASP.NET application which uses WebForms. What I did is that I just copy and paste the entire Default.aspx and Default.aspx.cs.
When I tried to build the application, it fails. I'm not sure what's wrong.
I'm curious about the DNX Core 5.0 which says the class it's not available there. What should I do? Anyways, here's my VS info:
Okay, got the problem right here. It's the project.json definition.
It seems I'm targeting multiple frameworks, just as Guruprasad said. Since I'm using WebForms, then I should use the full CLR instead of CoreCLR. Removing the "dnxcore50" did the trick.
Check your solution! If your solution has multiple projects then try setting the Target Framework of all the projects to be the same and clean and rebuild.