Use .net core with legacy .net DLL frameworks

Can I use .net core with legacy .NET DLL frameworks? The answer seems to be no ... but I can find resources related to project.json that no longer exists.

I created a new .net core library and tried to reference the legacy .net DLL structure. When I tried to call the DLL vs2017 complained that I didn't have the Stream object they were looking for.

I suggested a link to mscorlib.dll or installu Nuget.

The quick help could not find the reference for mscorlib.dll. If I manually link to it, I get the following error:

The "TargetFrameworkAttribute" type exists as in "mscorlib", Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 'and' System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a 'C: \ Users. .. \ AppData \ Local \ Temp.NETCoreApp, Version = v1.1.AssemblyAttributes.cs

NuGet Package - Microsoft.NETFx2.0. Quick help can't install it. If I run it from the command line:

> PM> install-package microsoft.netfx20   GET
> https://api.nuget.org/v3/registration2-gz/microsoft.netfx20/index.json
> OK
> https://api.nuget.org/v3/registration2-gz/microsoft.netfx20/index.json
> 46ms Restoring packages for ... Install-Package : Package
> Microsoft.NetFX20 1.0.3 is not compatible with netcoreapp1.1
> (.NETCoreApp,Version=v1.1). Package Microsoft.NetFX20 1.0.3 supports:
> net20 (.NETFramework,Version=v2.0)At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
>     + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Install-Package : One or more packages are incompatible with
> .NETCoreApp,Version=v1.1.At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
>     + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Install-Package : Package restore failed. Rolling back package changes
> for .At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
>     + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Time Elapsed: 00:00:00.8035644

      

+3


source to share


1 answer


Difficult topic. Typically .NET Framework and .NET Core are not compatible. They target a different set of assemblies (mscorlib vs. System.Runtime), which causes incompatibilities because all usage types are prefixed with the assembly from which the type is.

Starting with .NET Core 2 (currently in preview), you can reference .NET Framework assemblies through invisible compatibility. This allows you to successfully reference the assembly and compile.



This does not guarantee that the application will run successfully, as .NET Core does not provide all of the .NET Framework APIs. You will get PlatformNotSupportedException

or MissingTypeException

and friends at runtime if so.

+6


source







All Articles