Search code examples
entity-framework-coreasp.net-core-mvc

ASP.NET Core MVC : hostpolicy.dll required


As you all remember, after encountering many errors, I wrote the procedure to create ASP.NET Core MVC web sites, in the database-first flow, here:

Create an ASP.NET Core MVC application with database-first approach

(once on the page, please search for "This is the procedure").

I applied that at least twenty times with no problem, but this time, when doing exactly the same, I meet a compilation error, and I should like someone to find an explanation, why my procedure was quite OK the first twenty times, but not this time.

Here is the history of this project (first version of my question).

Do not forget that it is an ASP.NET Core MVC site, so I expected it to be published as such, rather than giving me news of a DLL of which I completely ignored it existed.

I created an ASP.NET Core 8.0 MVC project. There was no problem to add NuGet packages Microsoft.EntityFrameworkCore, plus the three others with names that begin the same and end respectively with Design, SqlServer, Tools.

No problem to get the connection string from the Server Explorer. Scaffold-DbContext and the connection string, OK.

In the Models folder of the solution explorer, I fail to add an EF Core database-first wizard: hostpolicy.dll required.

I saw here that the problem already appeared with .NET 2.

It was already noticed that "the error message is unhelpful", and it was needed to add an option in appname.runtimeconfig.[dev.]json, but I see no file of this name in my project, do you think the solution can be adapted, or do you see another?

Even when adding ".NET 8" at the beginning of the search query, I obtain the same answer first.

Here is the full error message:

Table list error: a fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\User\AppData\Local\Temp\efreveng7.2.6.287'.
Failed to run as a self-contained app.

The application was run as a self-contained app because 'C:\Users\User\AppData\Local\Temp\efreveng7.2.6.287\efreveng70.runtimeconfig.json' was not found
If this should be a framework-dependent app, add the 'C:\Users\User\AppData\Local\Temp\efreveng7.2.6.287\efreveng70.runtimeconfig.json' file and specify the appropriate framework


Solution

  • Oh well, such a long story ... I restored a backup, but it seems it was made just a little too late, I still had the error message that motivated the creation of this thread. I installed .Net 8, saw that the version number was the same for the one installed on Windows as for the one installed in Visual Studio. I remember I then had to repair the one on Windows. When wanting to create a new element in the Controller folder, I still only had two types of controller proposed, not the one with Entity Framework. I create a controller with read/write actions. It is not the one I want, so I create a HomeController, that is named automatically HomeController1 to avoid doubloons. From that controller, I right click in an action (Index, for instance), and I ask to add a view. There, I see a dialog box with a tree-view on the left. Under MVC, the Razor views are proposed in the View node. Just under the View node, I have a Controller node. In this Controller node, on the right of the dialog box I see the three controllers types I expected, including MVC Controller with Views, using Entity Framework. With that, I obtain the dialog box to select the classes for the controller, and when I validate I obtain the default views I expected.

    Perhaps you will admit that this is somewhat strange. As I obtained the final result I wanted I can mark the thread as solved.

    Considering the strange scenario, if somebody is interested I can provide screen copies in French. And of course if someone knows how I can go back to the normal scenario I am interested.