ASP.NET core 3.1 :Adding Classes Libraries to the Project_ MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations - asp.net-core

I'm working on asp.net-core 3.1 project, I have added 3 Class Library for my project to separate Access Data, Models class and Utility classes I resolved problems of matching folders etc. But when I run my project I get this Error:
MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences(Microsoft.EntityFrameworkCore.Metadata.IModel, Microsoft.EntityFrameworkCore.Metadata.IModel)'.
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext
httpContext)
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine
stateMachine)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<TStateMachine>(ref TStateMachine
stateMachine)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext
httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

For me, the answer was to make sure all of my EF packages were pointing at the same 3.1.X version. I had inadvertently targeted a 5.0.0 EF package that included the missing method:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.migrations.imigrationsmodeldiffer.hasdifferences?view=efcore-5.0

A straight forward fix for me in Dotnet core 3.1 is to comment out
app.UseDatabaseErrorPage();
in the startup.cs file Configure Method

I found a solution can Help for ERROR:
MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferenc
https://github.com/dotnet/efcore/issues/22687

Related

TypeLoadException exception on signout after upgrading to aspnet core 3.1

I use IdentityServer4 for auth which gets installed with Asp.net core web project in visual studio 2019. After upgrading to asp.net 3.1, I get below error on SignOut. I tried force update all the Nugets to latest. Still, I couldn't make it work. Appreciate any workaround.
TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.IReadableStringCollectionExtensions' from assembly 'IdentityServer4, Version=3.1.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b'.
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.AutoRedirectEndSessionEndpoint.GetParametersAsync(HttpRequest request)
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder<TResult>.Start<TStateMachine>(ref TStateMachine stateMachine)
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.AutoRedirectEndSessionEndpoint.GetParametersAsync(HttpRequest request)
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.AutoRedirectEndSessionEndpoint.ProcessAsync(HttpContext ctx)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I fixed this by reverting the IdentityServer4.EntityFramework reference from version 3.1.0 to 3.0.2, it would seem that the missing type is not yet implemented in 3.1.0.
I spent a few days researching this for work and I was unable to find any official documentation with regards to the problem or to the missing type. So the solution came from exasperation more than anything else. I apologize that I cannot provide you with adequate reasoning as to why it needs to be reverted, just that by doing it I fixed it.
for me
I have DAL has
IdentityServer4.EntityFramework and IdentityServer4
also the layer of ClientSlide has IdentityServer4 package changes all them to 3.0.2 instead of 3.1.0 solves the issue
For me the problem was resolved by uninstalling the Nuget package IdentityServer4 version 3.1.1 and letting the framework use the builtin one with version 3.0.0.

Running dotnet ef without Visual Studio throws an exception

I have a project that is a .NET Core console application with just a model and some seed data. On a development desktop I can go to the application directory, run dotnet ef database update and everything is fine (I need to copy appsettings.json to bin\... directory, but OK).
The problem is when I need to run this in the client environment (with VPN access, and without Visual Studio there). First, I am not sure what exactly I need to copy to the remote machine. But let's say, I copied the whole project. First, when I run, I get the following error:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools'.
I have a directory .nuget\packages\Microsoft.EntityFrameworkCore.Tools but not under .tools. Out of despair I created .tools and copied this directory under it, but now I am getting the following exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromToolLibrary(LibraryRange toolLibraryRange, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromAllToolLibraries(IEnumerable`1 toolsLibraries, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveFromProjectTools(String commandName, IEnumerable`1 args, String projectDirectory)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CompositeCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CommandResolver.TryResolveCommandSpec(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Utils.Command.Create(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
Clearly, my trial and error attempts to find the right way hit a wall. Is there some substantive (not just syntax) documentation as to how to run EF Core commands outside Visual Studio? .NET is version 1.1 if that matters
It seems that you have not removed Entity framework completly hence the error that path: .nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools is not found.
Somewhere in code there must be a reference to this file. If you are using project.json try checking your tools and depenedencies for Microsoft.EntityFrameworkCore.Tools.
If you are using the .csproj SDK version. Check your project file for any of these references and remove them.

running asp.net5 application using latest dnx version fails

I pulled the latest code from https://github.com/aspnet/MusicStore/tree/dev
Without making any changes to the code. I built the application for
dnx version : 1.0.0-rc2-16308 coreclr x64
The application builds successfully , however when I try to run the application,
I get the below error.
System.NullReferenceException: Object reference not set to an instance of an object.
at Xunit.Runner.Dnx.Program.GetAvailableRunnerReporters()
at Xunit.Runner.Dnx.Program.Run(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Please Note , The same code base worked successfully couple of days back.
We're in the process of migrating from dnx to dotnet. The migration happens on the dev branch so all the code there might not compile or fail at runtime. This is most likely one of those cases.
From the callstack I assume you're trying to run the tests. In the dotnet world, we run tests a little different and we haven't got yet to MusicStore with the conversion.
Sorry for the inconvenience.
RC2 is not stable. Downgrade to RC1
https://github.com/aspnet/MusicStore/releases

ASP.NET 5 Empty App IRuntimeEnvironment Error

I have an ASP.NET 5 Beta 7 Application and it uses MVC but even when I comment everything out the appication throws this error. It worked fine one day and started displying this error the next. Any help or even pointers on where to look would be appriciated.
[InvalidOperationException: Failed to resolve IRuntimeEnvironment]
System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +303
[HttpException (0x80004005): Failed to resolve IRuntimeEnvironment]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9924184
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
Thank you!
You probably ran the following command and got a new runtime:
dnvm update-self
Run the following command to set the runtime back to beta7 (even though it's outdated now)
dnvm use 1.0.0-beta7 -r clr -arch x86 -p
now you should be able to run
dnu restore
dnu build
dnx web

Windows Azure intermittent Identity error when parsing webconfig

This issue happens seemingly randomly after publishing.
The site will work fine and then bam, I get this error parsing the webconfig. I just republish and it works fine for a bit again. When publishing, I checked the box to remove existing files so there shouldn't be garbage laying around.
This is an MVC4 project using .net 4.5 and Azure Access Control Service (ACS) integrated with Yahoo!. This error occurs when redirecting back from Yahoo. This way happening every time, but I found a post (which I can not find now, of course) where there was a bug with the 4.5.1 Identity and Access Visual Studio integration. I went to the previous version and now it's only sometimes.
ID8030: The value of the 'type' property could not be parsed.
Verify that the type attribute of '<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry"><authority name="[my authority]"><keys><add thumbprint="[print]" /></keys><validIssuers><add name="[issuer]" /></validIssuers></authority></issuerNameRegistry>' element is correct.
In the above error message, I have replaced the items in brackets ([]) for this post.
Here is the stack trace:
[TypeLoadException: ID8030: The value of the 'type' property could not be parsed. *** element is correct.]
System.IdentityModel.Configuration.TypeResolveHelper.Resolve(ConfigurationElementInterceptor customTypeElement, Type customType) +602659
System.IdentityModel.Configuration.IdentityConfiguration.GetIssuerNameRegistry(IssuerNameRegistryElement element) +114
System.IdentityModel.Configuration.IdentityConfiguration.LoadHandlerConfiguration(IdentityConfigurationElement element) +841
System.IdentityModel.Configuration.IdentityConfiguration.LoadConfiguration(IdentityConfigurationElement element) +117
System.IdentityModel.Configuration.IdentityConfiguration..ctor(String identityConfigurationName) +180
System.IdentityModel.Services.Configuration.FederationConfiguration.LoadConfiguration(FederationConfigurationElement element) +392
System.IdentityModel.Services.Configuration.FederationConfiguration..ctor(Boolean loadConfig) +94
System.IdentityModel.Services.FederatedAuthentication.CreateFederationConfiguration() +71
System.IdentityModel.Services.FederatedAuthentication.get_FederationConfiguration() +85
System.IdentityModel.Services.HttpModuleBase.Init(HttpApplication context) +56
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): ***... element is correct.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I had the same issue when running local. I was going through the How-To found here: http://msdn.microsoft.com/en-us/library/jj161104.aspx and would get the type not found error on that assembly.
I double checked to make sure I pulled down the assembly via NuGet and even uninstalled and reinstalled it... no dice. It basically boiled down to a missing reference to the System.IdentityModel.Tokens.ValidatingIssuerNameRegistry
So, if you did pull this down via NuGet and you still have the issue, remember that when NuGet drops this package, it will throw it in a packages folder that's at the solution level in the file system.
If your project doesn’t show a reference to System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, add the assembly to your project by right clicking the project, select Add Reference, Browse, then click the Browse button and then browse up to the packages folder and find the dll ([Your Solution Root]packages\System.IdentityModel.Tokens.ValidatingIssuerNameRegistry.4.5.1\lib\net45) and add it.
I hope this helps.
I ran into the same issue but it was constant for me, not sporadic, so perhaps a different underlying root issue.
I was able to fix the issue though by installing the following NuGet package in my MVC 4 project:
http://www.nuget.org/packages/System.IdentityModel.Tokens.ValidatingIssuerNameRegistry/
I can't remember if this was added by default in a new MVC 4 project. I did at one point remove it so perhaps it may have been removing then reinstalling that resolved the issue. Either way, by adding the package above back I was able to get my MVC 4 project working with ACS correctly.
Hope it works for you as well.
I just had the same problem. One way to solve it is to add a reference to the DLL specified in the other posts.
Another option is to replace the section with this one, that uses a class available in the core .Net Framework 4.5 (you must add a reference to System.IdentityModel too):
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="[print]" name="[issuer]" />
</trustedIssuers>
</issuerNameRegistry>