I'm using the ASP.NET Core Authentication.OAuth package (version 2.2.0) to develop middleware for a unique authentication flow in my web app. I am using .NET Core 3.1. I'm running into several issues where it seems that there are constructors/methods missing from the package's base code, creating missing method exceptions that I cannot resolve (for example, this exception, which I've gotten around but haven't truly resolved: "MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.Authentication.OAuth.OAuth CreatingTicketContext..ctor" which I got when trying to instantiate an OnCreatingTicketContext object). I've tried uninstalling and re-installing the OAuth package, so I don't believe it's a problem with my specific installation. Although I've managed to work around some of these errors, I'm presently unable to instantiate new OAuthTokenResponse objects in my extended OAuthHandler class.
Calling OAuthTokenResponse.Success(response) produces a missing method exception ("Method not found: 'Microsoft.AspNetCore.Authentication.OAuth.OAuthTokenResponse Microsoft.AspNetCore.Authentication.OAuth.OAuthTokenResponse.Success(Newtonsoft.Json.Linq.JObject)'"). If I try to directly specify each of the object's fields (as below), I am met with another error: "'OAuthTokenResponse' does not contain a constructor that takes 0 arguments".
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
var result = new OAuthTokenResponse()
{
Response = payload,
AccessToken = payload.Value<string>("access_token"),
TokenType = payload.Value<string>("token_type"),
RefreshToken = payload.Value<string>("refresh_token"),
ExpiresIn = payload.Value<string>("expires_in")
};
Indeed, it seems from the class definition that there is no constructor defined taking any number of arguments, though I suspect that it exists and just isn't accessible, so maybe that's to be expected. Whatever the case may be, I don't know what to do and I can't tell whether it's something I'm doing wrong or it's a problem with the package itself. Any insights?
This problem sprouted from having multiple references to the same set of packages. I had not realized that ASP.NET Core versions after 2.2 were not referenced by inclusion of Nuget packages and that the .NET Core 3.1 framework supplied the most recent versions. I uninstalled/deleted references to the version 2.2 packages and the problem vanished.
Related
I used the database first approach.
The model is right (or at least it looks like)
But I always get this error. Please, I've already tried so many things..
The full code of my program (and even sql script by which I create my database)
is here: https://github.com/AntonioParroni/test-task-for-backend-stack/blob/main/Server/Models/ApplicationContext.cs
Since I have a mac. I created my model with dotnet ef cli commands (dbcontext scaffold)
I can use my context. But I can't touch any DbSet..
public static void Main(string[] args)
{
using (ApplicationContext context = new ApplicationContext())
{
Console.WriteLine(context.Database.CanConnect());
var months = context.Months.ToList();
foreach (var month in months)
{
Console.WriteLine(month.MonthName);
}
}
//CreateHostBuilder(args).Build().Run();
}
It is not my first time using EF. And everything was working fine before, in many simple projects or tasks. While here.... It doesn't matter what I do (I even tried to rename all of my columns name, erase all tables except one, modify the context code, use the same steps from this project on a new, totally empty project..)
It is always..
Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
---> System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException() in System.Linq.dll:token 0x600041c+0xa
ect....
Here is my package reference file
"restore":{"projectUniqueName":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/Server.csproj",
"projectName":"Server","projectPath":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/Server.csproj",
"outputPath":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/obj/","projectStyle":
"PackageReference","originalTargetFrameworks":["net6.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},
"frameworks":{"net6.0":{"targetAlias":"net6.0","projectReferences":{}}},
"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net6.0":
{"targetAlias":"net6.0","dependencies":{"EntityFramework":
{"target":"Package","version":"[6.4.4, )"},
"Microsoft.EntityFrameworkCore.Design":{"include":"Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive",
"suppressParent":"All","target":"Package","version":"[5.0.0, )"},
"Microsoft.EntityFrameworkCore.SqlServer":{"target":"Package","version":"[5.0.0, )"},
"Swashbuckle.AspNetCore":{"target":"Package","version":"[5.6.3, )"}},
"imports":["net461","net462","net47","net471","net472","net48"],
"assetTargetFallback":true,"warn":true,
"frameworkReferences":{"Microsoft.AspNetCore.App":{"privateAssets":"none"},
"Microsoft.NETCore.App":{"privateAssets":"all"}},
"runtimeIdentifierGraphPath":"/usr/local/share/dotnet/sdk/6.0.100-preview.6.21355.2/RuntimeIdentifierGraph.json"}}
It's been already a few days. And I'm becoming really confused and mad.
Why is this happening.. and why there is not that much info about this type of error in the internet. Please, just point me in the right direction..
You have net6.0 target framework which is still not released while you have installed EF6 which is a previous iteration Entity Framework (mainly used with legacy .NET Framework projects) and you also have EF Core (a modern iteration of it) but older version - 5.0 (which you are actually using for your context, see the using Microsoft.EntityFrameworkCore; statements there).
Try removing EntityFramework package and installing preview version of Microsoft.EntityFrameworkCore.SqlServer (possibly just updating to the latest 5 version also can help) and either removing completely or installing preview version of Microsoft.EntityFrameworkCore.Design. (Also I would recommend to update your SDK to rc and install rc versions of packages).
Or try removing the reference to EntityFramework (not Core one) and changing target framework to net5.0 (if you have it installed on your machine).
As for why do you see this exception - I would guess it is related to the new methods added to Queryable in .NET 6 which made one of this checks to fail.
TL;DR
As mentioned in the comments - update EF Core to the corresponding latest version (worked for 5.0 and 3.1) or update to .NET 6.0 and EF Core 6.
I'm writing a console application in dotnet core 3.1 and using the Microsoft.Identity.Client library 4.14, and I have the following code:
result = await App.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.WithProofOfPossession()
.ExecuteAsync();
But I get Cannot resolve symbol 'WithProofOfPossession'. I can access it in an Net45 app, but not in the netcoreapp3.1 app. Why is that, and how can I fix it?
It's not supported yet
From their repository wiki (bold are mine):
This is a new feature introduced in MSAL 4.8. Currently it is supported only in .net 45 and for public client flows.
Also, not sure if this will also apply to you (because the method should be there anyway), but there was a bug (however fixed in 4.1 supposedly) which didn't expose the method:
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1715
After reviewing my options regarding saving JWT token, I chose Xamarin.Essentials Secure Storage.
Problem being that my app always breaks when trying to save a token within the storage with the following error:
"System.AggregateException has been thrown"
The details are as follow:
"Xamarin.Essentials.NotImplementedInReferenceAssemblyException
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation."
This clearly means that something went wrong in the installaion of the nuget package, so I:
Uninstalled and reinstalled the xamarin.essentials package.
Upgraded .Netstandard to 2.0, thinking that 1.6 wasn't compatible.
Checked if the package is referenced within the csproj file.
So forth, nothing.
For now, I have a TokenStorageController with the following lines of codes :
public bool SaveToken(string token)
{
if(token != null)
{
Preferences.Set(key, token);
if(Preferences.ContainsKey(key))
{
return true;
}
}
return false;
}
The RestService class from where the controller gets called looks like this :
//await SecureStorage.SetAsync("oauth_token", "booommmmmm"); // changed to this simply to check if my controller was the problem
TokenStorageController tokenStorage = new TokenStorageController();
await tokenStorage.SaveToken("boommmmm"); // where I get an error
And here is the exact line where the error occurs:
var loginTask = Task.Run(() => restService.LoginAsync(user)).Result;
If no solutions, I will remove all packages and reinstall them all. ONE BY ONE! I swear I'll do it!
And if no solutions at all, I will store the token within SQL as I already have a controller in place to do so.
I am a Xamarin and C# noob so bear with me please.
FYI: I am using a macOS client for testing purposes, as the cause could be that SecureStorage doesn't work for macOS apps.
Thanks!
Xamarin.Mac is not currently a supported platform, just iOS, Android, UWP.
The code is available for review at:
https://github.com/xamarin/Essentials/tree/master/Xamarin.Essentials/SecureStorage
So I'm trying to do some simple Geography stuff in an old .NET 4.6.2 project. I have EF 5 installed (not planning on upgrading to EF 6).
When I try and do some simple DbGeography.PointFromText("POINT 1 1", 4326); I get a Not Implemented Exception thrown.
e.g.
SqlServerTypes.Utilities.LoadNativeAssemblies (AppDomain.CurrentDomain.BaseDirectory);
var xxx = System.Data.Spatial.DbGeography.PointFromText("POINT(1 1)", 4326);
I thought EF 5 has this method in it and it's totally ok to use? (e.g. reference material about using DbGeograpghy).
Am I doing something wrong? Is it possible the wrong (old?) dll is getting used and therefore, thrown?
Update 1 (Possibly not a duplicate).
It was suggested that the issue is because DbGeography requires (from nuget) Microsoft.SqlServer.Types package. So I tried installing that from nuget, then making sure I 'load' these special dll's at the start of my test. Problem still existed.
Update 2
Using NuGet Microsoft.SqlServer.Types version 14.0.314.76 (current version as of the time of this post)
When setting up LightInject for an MVC controller I am getting an error when calling container.EnableMvc(); in the injector setup.
Error:
Method not found:
'Void LightInject.WebContainerExtensions.EnablePerWebRequestScope(LightInject.IServiceContainer)'
Source:
public static void Register() {
var container = new ServiceContainer();
container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
WebContainerExtensions.EnablePerWebRequestScope(container);
container.RegisterControllers();
container.Register<ISomeClass, SomeClass>();
container.EnableMvc();
}
Additional Information:
I am running the code locally through Visual Studio
The project is 4.5
My OS is Windows 10 (framework 4.5)
In the past when I have setup LightInject I have set the scope lifetime manually but the documentation, for general setup and MVC specific examples, has since changed. I came across one thread that mentioned this could be an issue with not including LightInject.Web as a dep, but I can see it listed as a dep for LightInject.MVC and in the list of references in the project.
Are there any other steps I can take to manually configure the lifetime or otherwise verify that this method is available before Enabling MVC?
The issue here was that I installed LightInject.MVC with NuGet. It lists it's dependencies as:
LightInject.Web (>= 1.0.0.4)
LightInject (>= 3.0.1.7)
The after I exhausted this being an issue with versions of .Net 4.5 and possible issues with async. I decided to manually update both LightInject.Web and LightInject to their newest versions. After the update it resolved the issue.
I will add this as a bug in the listed dependencies on the projects site.