Add support for FrameworkReference's
In .NET Core 3.0, FrameworkReference was added in place of using nuget packages for ASP.NET Core. This means that in the latest beta of LINQPad I cannot reference my ASP.NET Core 3.0 assemblies. When I do, I get the following runtime exception:
Could not load type 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' from assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The 3.0 version of the Microsoft.AspNetCore.Hosting.Abstractions assembly is no longer a nuget package, but rather a FrameworkReference and is located (on my machine) at:
C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.0.0\ref\netcoreapp3.0\Microsoft.AspNetCore.Hosting.Abstractions.dll
Could not load type 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' from assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The 3.0 version of the Microsoft.AspNetCore.Hosting.Abstractions assembly is no longer a nuget package, but rather a FrameworkReference and is located (on my machine) at:
C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.0.0\ref\netcoreapp3.0\Microsoft.AspNetCore.Hosting.Abstractions.dll
Comments
I the error when using the "Add connection => Choose datacontext" functionality and I get the error when loading an EFCore context via Linqpad reference:
Could not load type 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' from assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I have checked the box "Reference ASP.NET Core Assemblies" => It makes no difference.
I have checked the generated User-Query assembly with ILSpy, and there are no Aspnet Core references:
Any idea what we can do here?
Edit: Same when using the add connection functionality:
Another question regarding future .net core versioning:
Do you plan to allow specifying the TargetFramework of a linqpad script?
Ex.: netcoreapp3.0 or netcoreapp3.1
I have further debugged this issue and I think i have found the root cause.
Steps to reproduce:
1) Create a new plain asp.net core 3.0 web api project (dotnet new web
2) Add the following public type to the project and build the project:
3) Create a new linqpad query tab and add a reference to the test project dll
4) Add the following code:
At this point, everything works
5) Now lets add the following reference to the test project:
PackageReference Include="Hangfire.AspNetCore" Version="1.7.7"
6) Rebuild
7) Re-evaluate the linqpad query:
This is probably due to the reference of the hangfire project:
When adding the hangfire reference, linqpad seems to completely remove the asp.net core framework references:
When explicitly referencing Microsoft.AspnetCore.Hosting.Abstractions, the linq query does not even build:
In the previous setup, when I manually try to load "Microsoft.AspNetCore.Hosting.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"
it loads the 2.x assembly:
I guess linqpads UserLoadContext does some magic here?