error occurred while loading required library hostpolicy.dll - .net-core

I would to like update the database but when i run : 'update-datebase' or the command : `add-migiration' in the Package Manager Console it give this error
Failed to load the dll from
[C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.2.7\hostpolicy.dll],
HRESULT: 0x800700C1
An error occurred while loading required library hostpolicy.dll from
[C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.2.7]
Things that have been done:
Update .Net Core to 2.2.7
Remove .Net Core 3.
Run VS(2017 & 2019) in administrator mode
Update nucket packages
Microsoft.EntityFrameworkCore v2.2.6
Microsoft.EntityFrameworkCore.Tools V 2.2.6

Related

ASP.NET Nuget version error when deploying to Heroku

When I deploy to Heroku, I get an error stating that my Nuget version is not up to date. When I checked my Nuget version from the command line, it was 6.2.1.2, and I don't have Microsoft.ClearScript.V8 7.2.1 installed locally. Therefore, I think the issue is that Heroku doesn't have the right Nuget version for the buildpack, but I'm not sure how to remedy this. Other buildpacks throw errors earlier on.
Full error output:
-----> Building on the Heroku-18 stack
-----> Using buildpack: https://github.com/jincod/dotnetcore-buildpack#v2.1.300
-----> ASP.NET Core app detected
Installing dotnet
publish /tmp/build_ed54e936/RoundTheCode.GoogleAuthentication/RoundTheCode.GoogleAuthentication.csproj
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /tmp/build_ed54e936/RoundTheCode.GoogleAuthentication/RoundTheCode.GoogleAuthentication.csproj...
/tmp/build_ed54e936/.heroku/dotnet/sdk/2.1.300/NuGet.targets(114,5): error NU1401: The 'Microsoft.ClearScript.V8 7.2.1' package requires NuGet client version '4.9.0' or above, but the current NuGet version is '4.7.0'. To upgrade NuGet, please go to http://docs.nuget.org/consume/installing-nuget [/tmp/build_ed54e936/RoundTheCode.GoogleAuthentication/RoundTheCode.GoogleAuthentication.csproj]
! Push rejected, failed to compile ASP.NET Core app.
! Push failed

Why do I get build errors when attempting to build a .NetCore 3.1 class library with EntityFrameworkCore in Visual Studio 2019?

I've got a .Net Core 3.1 created in Visual Studio 2019 (C# .Net Core library).
I'm attempting to add EntityFrameworkCore thru NuGet package manager to the project.
When attempting to add I got some compatibility errors.
So we created the projects and added EntityFrameworkCore on a different system.
When attempting to build those project in Visual Studio 2019 on my system, I get the
following errors:
This is a snapshot of the .Net and .NetCore runtime and sdks installed on the machine:
Here are the results from dotnet restore:
(Partial Listing)
Foo.WPFApp>dotnet restore Determining projects to restore... :
warning NU1701: Package 'System.ComponentModel.Annotations 5.0.0' was
restored using '.NETFramework,Version=v4.6.1,
.NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7,
.NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2,
.NETFramework,Version=v4.8' instead of the project target framework
'.NETCoreApp,Version=v3.1'. This package may not be fully compatible
with your project. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202:
Package Microsoft.EntityFrameworkCore 5.0.0 is not compatible with
netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore 5.0.0 does not support any target
frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package
Microsoft.EntityFrameworkCore.Abstractions 5.0.0 is not compatible
with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.Abstractions 5.0.0 does not support any
target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202:
Package Microsoft.Extensions.Caching.Memory 5.0.0 is not compatible
with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.Extensions.Caching.Memory 5.0.0 does not support any target
frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package
Microsoft.Extensions.DependencyInjection 5.0.0 is not compatible with
netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.Extensions.DependencyInjection 5.0.0 does not support any
target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202:
Package Microsoft.Extensions.Logging 5.0.0 is not compatible with
netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.Extensions.Logging 5.0.0 does not support any target
frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package
Here are the results from a dotnet build:
(Partial Listing)
Determining projects to restore... ....csproj : warning NU1701:
Package 'System.ComponentModel.Annotations 5.0.0' was restored using
'.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2,
.NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1,
.NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of
the project target framework '.NETCoreApp,Version=v3.1'. This package
may not be fully compatible with your project.
[Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202: Package
Microsoft.EntityFrameworkCore 5.0.0 is not compatible with
netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore 5.0.0 does not support any target
frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202:
Package Microsoft.EntityFrameworkCore.Abstractions 5.0.0 is not
compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.Abstractions 5.0.0 does not support any
target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error
NU1202: Package Microsoft.Extensions.Caching.Memory 5.0.0 is not
compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.Extensions.Caching.Memory 5.0.0 does not support any target
frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202:
Package Microsoft.Extensions.DependencyInjection 5.0.0 is not
compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.Extensions.DependencyInjection 5.0.0 does not support any
target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error
Can someone help me identify the issue and fix it?
1) Try to clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.
2) disable any installed vs third party extensions under Extensions-->Manage Extensions-->Installed
Or use devenv /safemode to start a initial vs to test whether the issue happens again.
Also, please do not forget to delete every bin and obj folder before you install the nuget package.
If your VS2019 version is not 16.8.X, please update it because NET5.0 is applied since 16.8.
Besides, try to create a new net core app and then test whether the issue happens again.
I removed my previous answer since it was not valid.
This is compiled in Visual Studio 2019. It worked on 1 machine. When we brought solution over to another machine it did not work. Packages: EntityFrameworkCore, .SQL, and .Tools
Try cleaning bin/ and obj/ folders before recompiling the project in the machine where it's failing.
Try as well to compile it using dotnet build directly from the command line as well.

Unable to find package Microsoft.NETCore.App with version (>= 3.1.0)

I have .NET Core SDK 3.1.200 installed on my local machine.
I create a Asp.Net Core app (using Visual Studio) targeting netcoreapp3.1. I test it and it works fine.
But when I commit it to CI the build fails to get the nuget package:
##[error]The nuget command failed with exit code(1) and error(NU1102: Unable to find package Microsoft.NETCore.App with version (>= 3.1.0)
- Found 81 version(s) in MyGet [ Nearest version: 3.0.0-preview8-28405-07 ]
- Found 73 version(s) in NuGet [ Nearest version: 2.2.8 ]
.NET Core 3.1 was released in December 2019 so why is the package not on nuget?
What am I missing?
Update
The CI is Azure Devops Pilelines and the agents are Windows machines that have Visual Studio 2017 installed. .Net core sdk 3.1 is not installed on the agents
Method 1:
Add the following task in your yaml
steps:
- task: UseDotNet#2
displayName: 'Use .Net Core sdk 3.1.x'
inputs:
version: 3.1.x
Method 2:
If using template editor, add Use .Net Core task and provide the version over there
Note: Make sure this should be the first task of the pipeline configured

Unit tests work in Resharper but not MSTests

We recently moved to .NET Core 3.1, and then back to 2.2 until we could update some dependencies that did not work under 3.1. After this, tests in MS Test would not run due to the reason below.
[1/2/2020 1:32:44.790 PM] ---------- Discovery started ----------
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
- The following frameworks were found:
3.0.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
3.1.0 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.2.0&arch=x86&rid=win10-x86
. Please check the diagnostic logs for more information.
The tests run in Resharper.
I reinstalled .NET Core 2.2.8 SDK from here but that did not help. After installation I noticed that C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App did not have a folder for 2.2.8.
How do I get the tests to run in MS Test and/or get that folder populated (and why wasn't it populated after installing that version for that matter)?

Why can't I install Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.1 via nuget? Asp.NET CORE 2.0.1

I have added the reference to my project.csproj file as indicated on S.O. and in the ms docs tutorial:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
running dotnet restore claims to succeed. But the dotnet aspnet-codegenerator command can't be found and in the manage nuget packages, the CodeGeneration.Tools isn't installed and manually installing gives the error:
Package restore failed. Rolling back package changes for 'ContosoUniversity'.
This appears to be from a version compatibility issue that I don't understand or know how to fix. I have installed in my dependencies Microsoft.NETCore.App 2.0.3
and Microsoft.NETCore.APP 2.0.3 and everything else is 2.0.1. (CodeGeneration.Design, CodeGeneration.Utils etc... and running at Package Management Console Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools Throws the error:
GET https://api.nuget.org/v3/registration3-gz-semver2/microsoft.visualstudio.web.codegeneration.tools/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/microsoft.visualstudio.web.codegeneration.tools/index.json 166ms
Restoring packages for C:\Users\sticker592\Documents\Visual Studio 2017\Projects\ContosoUniversity\ContosoUniversity\ContosoUniversity.csproj...
Install-Package : Detected package downgrade: Microsoft.NETCore.App from 2.0.3 to 2.0.0. Reference the package directly from the project to
select a different version.
ContosoUniversity -> Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.1 -> Microsoft.NETCore.App (>= 2.0.3)
ContosoUniversity -> Microsoft.NETCore.App (>= 2.0.0)
At line:1 char:1
+ Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for 'ContosoUniversity'.
At line:1 char:1
+ Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Downgrading everything to 2.0.0 allows me to install CodeGeneration.Tools in Nuget but I still get the error: dotnet : No executable found matching command "dotnet-aspnet-codegenerator"
Go to "Manage Nuget Package for solution" in Nuget Package Manager and
In Package Source
.
Add below detail:
Name
"nuget.org"
source
"https://api.nuget.org/v3/index.json"
If this happens, the solution to the error is to run the command at the dos command prompt in the project folder directory instead of in Package manager console. Then you can scaffold your pages without the error until MS fixes this bug.
Proof:
C:\Users\username\Documents\Visual Studio 2017\Projects\ContosoUniversity\ContosoUniversity>dotnet aspnet-codegenerator razorpage -m Student -dc SchoolContext -udl -outDir Pages\Students --referenceScriptLibraries
Building project ...
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Student'
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\username\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[100403]
Entity Framework Core 2.0.0-rtm-26452 initialized 'SchoolContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
Added Razor Page : \Pages\Students\Create.cshtml
Added PageModel : \Pages\Students\Create.cshtml.cs
Added Razor Page : \Pages\Students\Edit.cshtml
Added PageModel : \Pages\Students\Edit.cshtml.cs
Added Razor Page : \Pages\Students\Details.cshtml
Added PageModel : \Pages\Students\Details.cshtml.cs
Added Razor Page : \Pages\Students\Delete.cshtml
Added PageModel : \Pages\Students\Delete.cshtml.cs
Added Razor Page : \Pages\Students\Index.cshtml
Added PageModel : \Pages\Students\Index.cshtml.cs
RunTime 00:00:15.33

Resources