dotnet / Scaffolding

Code generators to speed up development.
MIT License
639 stars 228 forks source link

Scaffolding Controller in Blazor Serverside broken #1359

Open MarkStruik opened 4 years ago

MarkStruik commented 4 years ago

Note: If filing an issue related to using Scaffolding within Microsoft Visual Studio, please file an issue on the Microsoft Developer Community instead of here. This can be accomplished from Visual Studio by clicking on Help > Send Feedback, and choosing the appropriate action.

Steps to reproduce:

When you create a code behind for a razor page.

image

Expected behavior:

be able to create an api

Actual behavior:

image image

Additional information about the project being scaffolded, such as:

Target framework(s):

image

Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding:

deepchoudhery commented 4 years ago

Were you using the razor component(Budget.razor) to create the api? We only support C# model classes for API controller creation.

MarkStruik commented 4 years ago

@deepchoudhery, I am using c#. I have used the scaffolding as shown above on the command line and also in visual studio.

I am using a regular poco class. the problem is that when another part in the solution. I think you are using reflection to get to the model and datacontext.

if i remove the partial class i dont get the error. but it seems strange i would get an error in my scaffolding for API to a totally unrelated class. somehow there is an error in the reflection part when finding the Datacontext ( also see the printscreen error above )

so for the page that is causing the issue: image

it's really just a partial class, but somehow it is breaking it: image

the solution is a blazor webhosted site with api's in the same server ( asp.net core 3.1 ) and because i had so much code for one of the pages i wanted to split it up.

let me know if you need any other information. ( i cannot share the project, but i could create a separate one which would have the same issue, but you can easily create )

deepchoudhery commented 4 years ago

I'll test some stuff and get back to you.

MarkStruik commented 4 years ago

Might be worth noting. I also use a custom namespace for the blazor page. Not sure it’s related. But it is not default.