Supporting an .Net Framework Lib in .Net Core 2.0 WebAPI - Error - asp.net-web-api

so basicly out complete company dataaccess is based in .Net Framework 4.6.
We are only on windows, so no problems here atm.
We have a new project in which I want to use .Net Core 2.0 and WebAPI but I have to use this "old" .net Framework lib.
When I add the reference and start my project I will get an error:
Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
As far as I googled it and understand, the dataasccess lib will try to get the win auth but this isnt available in .net core (obvious) any more.
I found the nuget Microsoft.Windows.Compatilibity and after installing the error is gone.
But another one comes up:
Exactly this error:https://community.oracle.com/thread/4139377
And the only solution to this seems to be to remove the MS.Win.Comp package...
So a bit of a circle.
Any ideas?

Related

.Net Framework 4.6.1 app Error: Google.Protobuf Could not load file or assembly

I created a proof of concept standalone .Net Framework 4.6.1 console app to test a TLS with Google Protobuf comms protocol. It worked ok until I moved comms code into a .Net Class library (DLL .Net Standard 2.0) and tried to load it from my main WPF .Net Framework 4.6.1 app. I get this exception:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Google.Protobuf, Version=3.21.9.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604' or one of its dependencies. The system cannot find the file specified.
Source=SrvComms
StackTrace:
at SrvComms.Master..ctor() in C:\src\SrvComms\Master.cs:line 22
at SrvCommsTest.MainWindow..ctor() in C:\src\SrvCommsTest\MainWindow.xaml.cs:line 27
What magic or evil is at play?
Many thanks in advance for ideas and hopefully solutions that do not involve migrating to later .Nets.
Steve
ok, so the DLL also needs to be .Net Framework 4.6.1. Thank you.

In Visual Studio 2019, .net Core 2.1, how do I add .net Framework assembly to the project

I am working in Visual Studio 2019, and .net Core 2.1.1.
I am currently working on trying to get Identity Server 4's WsFederation integrated. In the latest instructions I could find, he mentions adding System.IdentityModel to the app through the project.json. Project.json seems to be deprecated now in .net core projects, and I am having a hell of a time figuring out how to add a freaking .net assembly to my project. Do I really need to just copy the file into the project and reference, cause that just seems wrong.
Instructions I am using:
https://www.scottbrady91.com/Identity-Server/IdentityServer-4-SharePoint-Integration-using-WS-Federation
Seems to all come back to the project type. I had created the project with AspnetCore and so I couldn't reference any .net framework assemblies, because you can't go back once you have made that choice. However, if you create the project specifically under the .net framework, you can move forward into the core frameworks, and hosting libraries of core. Which then allowed me to pull in the System.IdentityModel assemblies I needed to continue forward.

Error upgrading from .Net Core 1.0.0 to 1.1.0

I have a .NET Core project which I am getting back to which was working fine. I ran a NuGet update which upgraded a number of items, mainly going from AspNetCore 1.0.0 to 1.1.0. The solution compiles fine, but when I run it, I get this exception in the browser:
FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Http.Features,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Adding Microsoft.AspNetCore.Http.Features in project.json does not fix the problem and I can find no reference to it. Does any one have a suggestion on resolving this?
I encountered the same problem after updating from 1.0.0 to 1.1.0 (ASP.NET Core Web Application (.NET Framework 4.6.2) x86) using Visual Studio Community 2017 RC.
My solution were to uninstall the Codegeneration design package:
Microsoft.VisualStudio.Web.Codegeneration.Design (1.0.0-msbuild1-final)
Update!
The faulty package has since been updated (1.0.0-msbuild2-final as of this writing). So instead of removing the package, tick "include prerelease" and update.
According to this site Announcing the Fastest ASP.NET Yet, ASP.NET Core 1.1 RTM the .NET Core 1.1 SDK needs to be installed. I assumed that I had already done that through a Visual Studio notification, but that wasn't the case. Once I installed it, the site worked.

Could not load type 'System.Reflection.IntrospectionExtensions', ASP.NET MVC 4 (RC), possibly Facebook C# SDK's fault?

I'm developing an ASP.NET MVC 4 (RC) website, runs great on my local dev box.
Deploying to my host (DiscountASP) required me to change <compilation targetFramework="4.5" /> to <compilation targetFramework="4.0" /> even though I bin deployed it.
The site operates fine, until someone who is logged into Facebook, or attempts to connect to my site using their Facebook account (which is nearly all, my membership system uses Facebook primarily), it throws an error:
Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Since it's beta, I'm not worried about leaving the error online at this time, you should be able to re-create the error on my site here.
It appears the Facebook C# SDK is throwing the error, but is it the SDK's fault, or the fact I had to change to 4.0 framework? How could I resolve this?
Update
From what I gather, the System.Reflection.IntrospectionExtensions are new to .net 4.5, which is not on my host. However, my project targets the .net 4.0 framework, and is bin deployed as such. On my development system it runs fine, on host it errors.
Turns out it was the fact I had the project targeting .net 4.5 when I added the Facebook C# SDK reference (and later changed the project to target 4.0).
I removed the reference, ensured my project was set to .net 4.0, and used Nuget to re-install the Facebook C# SDK. Resolved the problem immediately.

Reference issues in .NET 4.0 project to .NET 2.0 dll/project

I just starting to use Visual Studio 2010 and .NET 4.0. I created a new WPF project a DLL built for .NET 2.0. When I build the project, I get a bunch of warnings like this one:
The referenced assembly
"MicroFour StrataFrame Business...processorArchitecture=MSIL"
could not be resolved because it has a dependency on
"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies not in the targeted framework
or consider retargeting your project.
When I reference a project I created that targets 3.5, it can't find any of the namespaces (during compile), though they show up in the object browser and intellisense correctly shows them.
Is there something I'm missing that needs to be done to reference an older .NET assembly?
There is very little point in targeting the client profile for .NET 4.0. The download is 41MB, the full version is 48MB, only 15% bigger. Unfortunately it is the default in VS2010, just change it with Project + Properties, Application tab, Target framework combo.
The client profile does make a lot of sense if you target 3.5, the full install is ~350 MB. The huge difference is explained by the prerequisites, .NET 4.0 requires at least XP SP3 or Vista SP1. But 3.5 installs on any version of Windows > 2000. The 3.5 installer thus contains lots of the required updates for unmanaged Windows components used by .NET. The web installer lessens that blow considerably btw.
Your 2.0 assembly has a reference to System.Web. The reference is being automatically forwarded to your target framework, 4.0. So it is attempting to use System.Web, version 4.0.0.0. The problem is with 4.0 (actually this started with 3.5), there is now the notion of a client profile. The client profile has a smaller set of reference assemblies, anything web/server related has been removed. This is to make the .NET framework a smaller/simpler download for end users.
With VS 2010 and .NET 4, the client profile is being pushed a lot harder, MS really wants us to use it. So your .NET 4 project is targeting the client profile by default. Your referenced assembly wants System.Web, so in that case you need to switch to the full profile.

Resources