question

MyNguyen-0568 avatar image
0 Votes"
MyNguyen-0568 asked ZhiLv-MSFT edited

I have a problem with Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.9

When I add project reference and try adding Scaffolded, I get this error
243961-image.png


dotnet-aspnet-core-generaldotnet-runtimedotnet-package-management
image.png (166.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MyNguyen-0568,

Try to clean the solution/projects and then rebuild it, if there has no error, try to re-adding the Scaffold page.

It still meet the same error, can you tell us the details steps or what you do will reproduce the problem? And, your Visual studio version?

0 Votes 0 ·

Hi @ZhiLv-MSFT,
I use Visual Studio 2022 .NET 6.0 - ASP.NET Core Web App (Model-View-Controller)
GenZBookWeb - When I add project reference GenZBook.DataAccess and add new Scaffolded item MVC Area, it throws an error. I think there's something wrong with CodeGeneration.Design 6.0.9. I tried to clean the solution/projects, rebuild and re-adding the Scaffold page but the error still occurs. Hope the helping, tks!!!

0 Votes 0 ·

1 Answer

ZhiLv-MSFT avatar image
0 Votes"
ZhiLv-MSFT answered ZhiLv-MSFT edited

Hi @MyNguyen-0568,

GenZBookWeb - When I add project reference GenZBook.DataAccess and add new Scaffolded item MVC Area, it throws an error. I think there's something wrong with CodeGeneration.Design 6.0.9. I tried to clean the solution/projects, rebuild and re-adding the Scaffold page but the error still occurs. Hope the helping, tks!!!

Yes, you are right, the issue relates the CodeGeneration.Design package. I could reproduce the problem using 6.0.9 version, 6.0.8 version and 6.0.0 version. But it works well on asp.net 5 and CodeGeneration.Design 5.0.2.

This is a known issue, you can also feedback this issue to the Scaffolding forum, hope they can fix it in the next version.

As a workaround, you can try to the following steps:
1. Remove the DataAccess reference from the GenZBookWeb project
2. Create models (use the same name) in the GenZBookWeb projects
3. In GenZBookWeb projects, you can use Scaffold to add the generate pages
4. Remove the models from the GenZBookWeb project and re-add the DataAccess project reference. [Note] You need to change the model reference in the generated page.

Besides, you can also create a new project, which contains the Web and DataAccess model in the same project, then generate the page using Scaffolded, after that you can copy the generated page to the GenZBookWeb project.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Dillion

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.