I have created a Custom Model Binder in .NET Core 1.x . It works well as shown in the official tutorial.
Once updated to 2.0, I can't compile it anymore. In the old version it was
return TaskCache.CompletedTask;
Now the TaskCache static class isn't available anymore.
Does any know a workaround?
TaskCache.CompletedTask was removed in .Net Core 2. Instead just use Task.CompletedTask.
Related
I am getting a little confused by all the naming and versioning of .NET. I think I understand the whole .NET Framework / Standard / Core thing, but I am now moving into ASP.NET Core territory (I want to give my console application a web interface with Kestrel).
When using the NuGET package manager, I can see the Microsoft.AspNetCore.Hosting package, needed to run the webserver. But the highest available version is 2.2.7.
Question now, is that 2.2.7 part of ASP.NET Core 5.0, or do I have some configuration incorrect that I do not get the latest version for my application?
And if it is indeed part of ASP.NET Core 5.0, where can I find that reference? This table helped me a lot with understanding the core libraries.
I assume you wanna this document which tells about your package :
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting?view=aspnetcore-5.0
And I think you can focus on those classes or interfaces you'll use and take a look if those are supporting .net 5 by click and refer to the details page. You'll see Applies to at the bottom of each page such as this one.
If I misunderstood in some place which made my post isn't suitable to display here, pls point it out and I'll delete it.
I have a custom authentication component that is working with net core 2.2. I've started migrating the project to net core 3, but it seems like MS hasn't updated the authentication Nuget packages.
Until now, I was referencing the Microsoft.AspNetCore.Authentication package. The package still exists, but hasn't been updated to net core 3.0 (it's still on the 2.2 version).
I can't keep using it because net core 3.0 has moved the RequestPathBaseCookieBuilder type to a different namespace (so, at runtime, I'll get a tyoe loading exception). A quick search shows that only the Microsoft.AspNetCore.Authentication.OpenIdConnect has been updated to net core 3.0 (and if I add it to my project, then my component to work without any issues).
Anyone knows why MS hasn't still updated the other security nuget packages to version 3? Is there anyway to solve this without using the openidconnect nuget package (I'm only using it because it was the first that was updated and it will bring the correct Microsoft.AspNetCore.Authentication assembly that I need for my project)?
Looks like I was 10 minutes too late, but you posted the answer as a comment, rather than an answer, and I like questions having answers so I stop opening them when browsing the question search results.
Anyway, as you discovered, .NET Core 3.0 no longer uses packages for base class libraries (BCLs). Instead, they're just part of the SDK, so by targeting netcoreapp3.0 or netstandard2.1, all BCLs are just available. This should eliminate a lot of problems that earlier .NET Core projects had, particularly when referencing .NET Standard 1.x assemblies from netcoreapp2.x tfms. Although the largest benefit will be when all referenced packages target netstandard2.1 or netcoreapp3.0 or above.
Ok, so finally got it. The solution is to use the FrameworkReference element with the Microsoft.AspNetCore.App meta package.
I am using VS Pro Update 3
I have been following the guide here: https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx
I have 3 existing .NET 4.5.1 Class Libraries, written in VB.NET but I don't think that should matter as it's all on CLR.
My ASP.NET Core project is C#, targeting .NET 4.5.1.
Here is the Framework section of my project.json:
"frameworks": {
"net451": {
"dependencies": {
"WebApp.Api.Services": {
"target": "project"
}
}
}
},
If I add all my VB.NET class libraries using Add Existing Project to my solution and try to add them as project reference, I get the following error:
Project XXX type is unsupported by current project and cannot be added
as a reference
I also tried adding a C# class Library (WebApp.Api.Services), add VB.NET references to that, then add the C# Class Library as a reference to the ASP Core project
Doing this shows the references in Solution Explorer okay, it seems as though I can use types from the C# Class library but I can't use the VB.NET library's types in my code.
I also created a NuGet package, but no luck
I have read that you can create a 'wrapper' project somehow, or Visual Studio can do this automatically.
Has anyone ever tried adding VB.Net projects to ASP Core solution?
A project built for .NET Core cannot use class libraries built for .NET Framework. They are not directly compatible with each other. In fact I'm confused when you say:
My ASP.NET Core project is C#, targeting .NET 4.5.1.
If it's targeting .NET 4.5.1, then it's not actually a .NET Core project.
You should port your class libraries to .NET Standard; that way they can be used by a wide range of compatible frameworks. It is also possible to have a class library target multiple frameworks.
I managed to solve my issue.
The guide here is correct, I had another different issue that I didn't realize.
I found a System.BadImageFormatException error which lead me to the following question Start an asp.net core project as x86 under visual studio 2015
I uninstalled the x94 version of .NET Core and installed the x86 one.
I still could not add references to the VB.NET libraries to the ASP Core project, so my C# services 'Bridge' library was vital.
In my 'Bridge' library I have Models that I can return from my ASP Controllers:
Public BridgeModelA : VB.NETLibrary.ActualModelA
{
…
}
Then extensions
Public static VB.NETLibrary.ActualModelA ToModel(this BridgeModelA)
{
…
}
Although the base members of these models cannot be accessed in the controllers, due to ASP proj not referencing the VB projs, they are returned by the controller with JSON result containing all base members.
This is actually great as it fits in with the design of thin controllers.
Need to embed a json file as a source for testing in my .NET Core application. The author of this post http://codeopinion.com/asp-net-core-embedded-resource/ provided sample code that included the use of var assembly = Assembly.GetExecutingAssembly();However when I try this I get the error: Cannot resolve symbol ‘GetExecutingAssembly’ and ‘Assembly’ does not contain a definition for ‘GetExecuringAssembly’
If you are targeting .NET Standard 1.5 or above, you may call any of the following:
System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.Assembly.GetEntryAssembly();
System.Reflection.Assembly.GetCallingAssembly();
If targeting earlier versions of .NET Standard then the typeof(SomeClass).GetTypeInfo().Assembly method is the only way.
There is no "static" Assembly class in .NET Standard prior to version 1.5. Instead you have to do something like:
typeof(<AClassHere>).GetTypeInfo().Assembly
Where <AClassHere> should be replaced by the name of a class/type in the assembly you wish to load.
Nope, it's not available in .NET Core 1.0/1.1.
However, if I remember correctly it will be back in .NET Core 2.0 and the netstandard2.0 which is to be released later this year, which will have a much bigger API surface and increased compatibility with libraries written against .NET >= 4.5 making it easier to port these to .NETStandard 2.0/2.1.
But many of the APIs implementations will be platform dependent. Means, you will be able to call SomeAPI.GetSomething() everywhere, but if run on .NET Core it may throw a PlatformNotSupportedException.
But most APIs about assembly scanning and discovering should be back in .NET Core/Standard 2.0. Stuff around AppDomain will still be missing as there are no AppDomains in .NET Core and processes should be used for isolation.
I am trying to port project to .NET Core. But I can't find analog System.Dynamic.ExpandoObject.
The ExpandoObject class lives in the System.Dynamic.Runtime package, along with DynamicObject and other dynamic infrastructure types.
Tip: you can use this package search website to find types in .NET Core - it still works with RC2 packages but just download the stable version in stead of *-rc2.