cannot add controller in .net RestApi - c#

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

Related

JsonApiDotNetCore 5.0.1 Breaks with latest version of Visual Studio 2022 (Version 17.3.0)

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.

How can you create MVC and Web API project in the same project in JetBrains Rider?

I am want to create a .NET Framework project that has API and MVC parts to it. In Visual Studio there are checkboxes that I can select but in Rider there is nothing, it only allows me to create an MVC project.
I know I can just reinstall Visual Studio and do it from there but I really want to know if there is a way to do this.
With .Net Core I can simply add an API controlller bt I don't know how to just add a controller.
If there is a way to add it manually, please tell me!
Rider screenshot:
As you can see, there is no place to add API. I can't even create a standalone API project!
Status
Someone suggested that I create a WebAPI separately and add the config later but I can't even create an API.
I looked up how to add an API and it tells you to add one line of config but the code throws errors. The question
You can just create it from the type combo:

ASP.NET appsettings.json does not exist in my project

I am following this guide on how to create a Web API with ASP.NET Core and MongoDB. I have followed every step successfully up until the Add a configuration model section. In the guide, I need to locate appsettings.json and add database configuration values to my project. The problem is that the file they mention appsettings.json does not exist in my project.
In the guide, its implied that the file should already exist and should even already have content in it, so I don't know if I should just create it.
I have looked online and all over my project but nothing seems to be definitive on what is the right thing to do (some guides contradict each other, etc.).
Apart from the default ones, I explicitly installed have the following NuGet packages:
Microsoft.Extensions.Configuration (I thought this might help, but it didn't)
MongoDB.Driver (the instructions on the guide said to)
My setup is the following:
Microsoft Visual Studio Community 2019 Version 16.4.6
Microsoft .NET Framework Version 4.8.03752
ASP.NET and Web Tools 2019 16.4.462.24200
ASP.NET Web Frameworks and Tools 2019 16.4.462.24200
I have closed and re-opened VS but that didn't change anything.
This is my solution explorer:
Should I just create the file? In the guide, it already has content in it. What about that?
Is there a new/different way of add database configuration values to my project?
Is the guide outdated? If it is completely unusable, can you point me to a newer guide on how to Create a web API with ASP.NET Core and MongoDB?
Thank you very much!
The app exists for ASP.NET core projects. You mistakenly created, I believe, an ASP.NET framewok project. The tutorial is about the ASP.NET core.

Creation of ASP.NET users in console application

I am currently looking to build a console app to interact with a .NET webservice and insert AspNetUsers into my database.
I'm currently using this: https://www.codepoc.io/blog/net-core/5291/create-aspnetcore-identity-users-using-console-application
As a guide. However, I'm a little confused when it comes to the various dependencies required to successfully run the aforementioned code.
My workspace currently looks like this:
Am I correct in assuming that I may have the wrong version of AspNetCore? Am I missing something else or is this blog post out of date now? What would the best way be to insert .NET Identity users into the database using a .NET core console app - I'm equally not opposed to keeping it as a .NET Framework? Console app.
Any guidance appreciated.
I think Microsoft.AspNetCore.Identity.dll is its own dll which you can download via nuget from here. Please add that nuget package to your solution. Microsoft.AspNetCore is a different dll that does not contain the Microsoft.AspNetCore.Identity namespace which is why you are getting the error and not able to resolve the reference.

Integrating ASP.NET 5 with WebForms

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.

Categories