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
Related
Currently I am using .netcore 3.1 project. Started migrating it to .net6.0
Below code is currently implemented in .netcore3.1
app.UseMvc(b =>
{
b.MapVersionedODataRoutes("odata-versioned", "odata", edmModels);
});
After migrating the framework to .net6.0 and I am getting error that MapVersionedODataRoutes is not available.
Are there a breaking changes? What is the new way of implementing the same.
Got stuck as the MapVersionedODataRoutes was not available
Do you want to implement API versioning? In OData 8.0.11, you can implement it by AddRouteComponents:
builder.Services.AddControllers()
.AddOData(opt => opt.AddRouteComponents("v{version}", edmModel));
For more details, you can refer to this link.
In addition, Microsoft.AspNetCore.OData.Versioning contains a MapVersionedODataRoute property, which may help you.
Error:
Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I am migrating an Azure Function V1 to an Azure Function version 4 running .net 6 that references .net framework 4.8 code. The azure function code is rather basic because it passes off most the functionality to the 4.8 code.
The 4.8 code does all the real work. This includes database functions with EF 6, calls to web APIs etc.
Example of writing to database (Reading cases same problem)
public void WriteInfo(string message, int merchantid, int merchantchannelid, string logicalThread, string level)
{
using (var db = new Repository(_dbConnection))
{
var log = new Model.Log
{
Date = DateTime.UtcNow,
Message = message.WriteToMaxLength(3999),
Logger = "Base",
Thread = logicalThread,
Level = level,
LogicalThreadId = logicalThread
};
db.Logs.Add(log);
db.SaveAllChanges();
}
}
Azure Function Code V4 running .NET 6
public class JobRunner
{
public static string jobquename = String.Empty;
private readonly IConfiguration _configuration;
public JobRunner(IConfiguration configuration)
{
_configuration = configuration;
DbProviderFactories.RegisterFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);
}
[FunctionName("JobRunner")]
public async Task RunAsync([QueueTrigger("%Queuename%", Connection = "jobqueueconnection")]string myQueueItem, Microsoft.Extensions.Logging.ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
var logger = new Logger();
var s = _configuration.GetConnectionString("dbConnection").ToString();
var repo = new Repository(s);
var f = new JobManager.CoreJobManager(s);
var result = await f.RunJob(Convert.ToInt32(12));
}
}
Additional notes: The 4.8 code is very extensive in what it does and in particular the EF framework being database first is the biggest stumbling block. Unless someone can suggest a way around using .net Standard with correct EF version I am pretty much stuck until we can dedicate the months it would take rebuild it with code first.
This currently works in the V1 azure functions but because of V1's weird issue with limited support for NewtonSoft JSON (9.01) we have been using a weird workaround using assembly replacement and would like to move to V4 which seems to support it.
A link to instruction for creating a 4.8 framework V4 function would also be great. I appreciate the help.
Miscrofts documentation for azure functions v4
Azure Function V4
When migrating the Azure Functions Code from .NET framework 4.8 to .NET Core, you need to check some things that should be compatible to the language runtime you choose like
Compatible Code and Libraries
Both the .NET Framework and Core supports 3rd Party Libraries but still, the .NET Core is doesn't compete with the .NET Framework.
Thanks to #JeroenMostert, as your suggested solution in the comments are correct and helpful.
under no circumstances will you be able to mix and match .NET 6 and 4.8 assemblies this way -- you still have to settle on one particular runtime version.
I would suggest that you create the new function app in a new version (.NET 6 Core / .NET 4.8 Framework Azure Functions Core Tools V4) and rewrite the same functionality code for the best migration result.
As Jeroen also said that you have to make note of the .NET 4.8 Framework Azure Functions v4 feature is in preview mode, you may encounter some issues while developing the project.
Refer to the .NET Framework 4.8 Azure Functions v4 Out-of-process guide for hosting the function app and the sample in the GitHub.
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.
I've just upgraded my ASP web API project from .Net core 2.0 to 3.0. I was using
services.AddMvc()
.AddJsonOptions(options =>options.SerializerSettings.ContractResolver
= new DefaultContractResolver());
previously to ensure lower-casing of the serialized JSON.
After the upgrade to 3.0 I get this error:
Error CS1061 'IMvcBuilder' does not contain a definition for
'AddJsonOptions' and no accessible extension method 'AddJsonOptions'
accepting a first argument of type 'IMvcBuilder' could be found (are
you missing a using directive or an assembly reference?)
According to AddJsonOptions for MvcJsonOptions in Asp.Net Core 2.2 the AddJsonOptions extension method is/was provided by the Microsoft.AspNetCore.Mvc.Formatters.Json nuget package. I have tried installing/reinstalling this but still can't resolve the method. Interestingly, intellisense only shows Microsoft.AspNetCore.Mvc.Formatters.Xml when I try to add the using statement even though I added the Json nuget package.
Any ideas what is going on? The documentation for AddJsonOptions only goes up to .Net 2.2 so perhaps the method has been deprecated in 3.0 in favor of some other configuration mechanism?
As part of ASP.NET Core 3.0, the team moved away from including Json.NET by default. You can read more about that in general in the announcement on breaking changes to Microsoft.AspNetCore.App.
Instead of Json.NET, ASP.NET Core 3.0 and .NET Core 3.0 include a different JSON API that focuses a bit more on performance. You can learn about that more in the announcement about “The future of JSON in .NET Core 3.0”.
The new templates for ASP.NET Core will no longer bundle with Json.NET but you can easily reconfigure the project to use it instead of the new JSON library. This is important for both compatibility with older projects and also because the new library is not supposed to be a full replacement, so you won't see the full feature set there.
In order to reconfigure your ASP.NET Core 3.0 project with Json.NET, you will need to add a NuGet reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson, which is the package that includes all the necessary bits. Then, in the Startup’s ConfigureServices, you will need to configure MVC like this:
services.AddControllers()
.AddNewtonsoftJson();
This sets up MVC controllers and configures it to use Json.NET instead of that new API. Instead of controllers, you can also use a different MVC overload (e.g. for controllers with views, or Razor pages). That AddNewtonsoftJson method has an overload that allows you to configure the Json.NET options like you were used to with AddJsonOptions in ASP.NET Core 2.x.
services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
This worked for me, while using .Net Core 3:
services.AddMvc().AddJsonOptions(o =>
{
o.JsonSerializerOptions.PropertyNamingPolicy = null;
o.JsonSerializerOptions.DictionaryKeyPolicy = null;
});
Make sure that you installed the Microsoft.AspNetCore.Mvc.NewtonsoftJson package.
It's work for me, Install the NewtonsoftJson package from NuGet "dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson --version 3.1.0" version 3.1.0 working for ASP.NET Core 3.0 and use the Following Code-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(opt => {
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
Hope it's Working Fine, Thanks.
This would help
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddJsonOptions(options=> { options.JsonSerializerOptions.PropertyNamingPolicy = null;
options.JsonSerializerOptions.DictionaryKeyPolicy = null;
});
services.AddDbContext<PaymentDetailContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));
}
This would help try Installing the Nuget Package
Microsoft.AspNetCore.Mvc.NewtonsoftJson
This worked for me, while using .Net Core 3:
click here
Having the code below in VisualStudio 2017 .NET Core 2.0 Console App
using System;
using System.Security.Principal;
namespace smallTests
{
class Program
{
static void Main(string[] args)
{
var identity = WindowsIdentity.GetCurrent();
}
}
}
Why am I getting the error:
The name 'WindowsIdentity' does not exist in the current context
If I can see this class in .NET Core 2.0 library in .Net Core docs ?
Same code works in .NET Console app.
[EDIT]
#Will #JohnnyL Commented that I do not refer, System.Security.Principal.Windows.dll, that is true.
But I am curious why it is not working, because
in .NET 4.6.1 project (where class WindowsIdentity is visible) I also do not refer this System.Security.Principal.Windows.dll specifically. However i refer System.dll.
I always thought that it works like namespace hierarchy. For instance, when I refer to
System.Security.Principal.dll
i can use class which is in
System.Security.Principal.Windows.dll.
Am I wrong?
I added System.Security.Principal.dll to .NetCore solution by hand but it still does not work.
[EDIT2]
#Will Thank you a lot for expaining the subject it helped me a lot.
I tried to figure out is WindowsIdentity compatible with Core and it seems that it is please see:
in this apisof.net in Declarations area i can see that WindowsIdentity is in .Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a
but i do not have System.Security.Principal.Windows.dll in references, should I add it? If yes from where?
in .NET Core api reference i see this class in the list (what is the purpose of that listing if it is not compatible with core?
I also find information about that class in that link
Am I looking in wrong places?
Microsoft announced Windows Compatibility Pack for .NET Core a few weeks ago,
https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/
And by analyzing the source code of System.Security.Principal.Windows.csproj and the commit adding it,
https://github.com/dotnet/corefx/blob/master/src/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
My conclusion is that this is also part of the Windows only compatibility libraries, so can only be used on Windows.
To add that to your project, open your csproj and add a PackageReference tag for System.Security.Principal.Windows manually (or use Visual Studio's NuGet Package Manager).