Core 2 error referencing Framework libraries - asp.net-core-2.0

I have a test project int Core 2 console (Core2ConsoleTest).
It make a reference to .NET Framework 4.6.1 Project (NetFrameworkTest).
NetFrameworkTest project references the standard System.Printer.dll.
Download Core2ConsoleTest project here
When I call to any System.Printer function I have the error: Could not load file or assembly 'System.Printing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. El sistema no puede encontrar el archivo especificado.
I tested with other standard libraries like System.Windows.Forms.dll and the same error if the Core project references a Nuget Package that uses standard libraries.
Note: The same error with ASP.Net Core 2
Thanks for your help!

This is not going to work on .NET Core.
.NET Core 2.0 has a compatibility layer that allows loading and using .NET Framework libraries but this only works as long as this library only uses types and methods that are also available on .NET Core.
Since System.Printing is not part of .NET Core, this library will fail to access it with the exception you posted.
Only .NET Framework applications can use this API (e.g. an ASP.NET Core on .NET Framework application).

I really have the problem with ASP.Net Core Framework Project. I'm unable to create a new Project with Core 2.0 and reference a Framework library that references System.Printing.dll or other libraries.
But #mairaw gave me another way: On a project that works in Core 1.1, updating the libraries Nuget to 2.0, works correctly.
So it looks like a Visual Studio 2017 problem or Core templates.
My concern is to remove this functionality, because it allows to adopt the Core technology in a staggered way with a high code reuse.
Edit: Added sample projects
CoreTest.zip -> A ASP.Net Core Framework Project created referencing Core 1.1 and .NET Framework 4.6.1 in the past, then upgraded to Core 2.0 using Nuget: WORKS!
Core2Framework.zip -> A similar project (ASP.Net Core Framework Project created referencing Core 2.0) created with Visual Studio 2017 15.3.4: ERROR when calling System.Prinig.dll from the .NET Framework 4.6.1 Project.

Related

Compatibility/ Documentation with ML.NET on MVC5

I've read online and watched some videos concerning ML.NET and the usage of it. All the videos and documentation that I've read online were on ASP.NET Core. I was wondering if it was possible to use the ML.NET on MVC5 (Since that's what we've been taught in class and have to use for our project)
If it is compatible are there any links or suggestions on how to go about it?
ML.NET requires .NET Core in version 2.1 (or newer) or .NET Framework version 4.6.1 (or newer):
First, ensure you have installed .NET Core 2.1 or later. ML.NET also works on the .NET Framework 4.6.1 or later, but 4.7.2 or later is recommended.
Source: GitHub page for ML.NET
As long as your app is running on one of those .NET implementations, you should be good to go. Regardless of the app type (ASP.NET, Winforms, ...).
You can find samples here.

VS Code + Develop(Linux) + Target(.net Framework) + Host(Windows)

I am developing a Web Application with ASPNET Core 2.0 on Visual Studio Code on Linux. But the host I'm trying to deploy the application is a Windows Server and the only target available option is .Net Framework 4.6.
So, when I try to run dotnet publish -o /folder -f net461 it shows me
this error.
Is it possible to develop an aspnet core application on linux and deploy it on windows using .Net Framework?
The following is the text of the error:
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/maransatto/Projects/FATEC/EraDoConhecimento/web/BDAg.csproj]
There are 2 scenarios: ASP.Net Core with .Net framework and ASP.Net Core with .Net Core. You can't develop asp.net core with .net framework on linux, so probably your application's target is "netcoreapp2.0" (suposed you downloaded the latest version). It's ok you deploy your app on windows server just using .net core runtime 2.0.
your command should be
dotnet publish -c Release -f netcoreapp2.0
You can deploy Framework-dependent or self-contained version. See (https://learn.microsoft.com/en-us/dotnet/core/deploying/index).
You also need Asp.Net Core Module on windows with IIS Integration.
https://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x
When publishing self-contained you don't need .net core to be installed on the server.

Is there any advantage to a .NET Core library over .NET Standard library?

I'm porting my applications from VS2015 to VS2017 and trying to figure out the right migration path. I'm also moving my web services to .NET Core to take advantage of deploying to Linux or Windows servers. I see that I have the option of creating base libraries in .NET Standard or .NET Core. Is there any advantage to a .NET Core library or should I create the base libraries in .NET Standard by default?
Practically speaking, .NET Standard 2.0 is the intersection of .NET Framework 4.6.2(-ish) and .NET Core 2.0.
If you build a library targeting .NET Standard 2.0 then your library can be consumed by .NET Framework libraries and applications, as well as .NET Core libraries and applications. That's the advantage of Standard.
But there are several types/members that have been added to .NET Core which aren't part of .NET Standard. If you want to use something like the new CertificateRequest class you'd need to explicitly target .NET Core.
.NET Core allows new things to get to users faster than .NET Framework does, so the general tradeoff will always be ".NET Standard => more places; .NET Core => newer things".
.Net Standard is just package with interfaces with can be used to provide compatibility across .Net Framework, .Net Core and others
I wouldn't choose a .NET Core library. The differences are in the referenced libraries:
the .NET Standard library references the netstandardX.X NuGet meta-package
the .NET Core library references the netcoreappX.X NuGet meta-package
The netcoreapp package also includes some .NET Standard packages, but also a bunch of .NET Core App specific packages (including libuv. Don't know why a library needs libuv.)
So the .NET Standard library is for cross platform and the .NET Core library just for .NET Core

Can ServiceStack run on .net core on Linux?

The documentation about Linux hosting only mentions mono. Can the new .net core and asp.net core (DNX) also be used?
ServiceStack now supports running on .NET Core from October 20, 2016 v4.5.2 Release.
Nearly all of ServiceStack’s features are now available across 21 of our most popular NuGet packages, inc. OrmLite support for SQL Server, PostgreSQL and Sqlite. We’ve been able to achieve excellent integration and code-reuse where your ServiceStack AppHost can be registered as a .NET Core module and most of your Service Implementation using ServiceStack libraries remains unchanged.
We’ve ported a number of existing Live Demos to .NET Core providing example projects so you can easily compare .NET 4.5 ServiceStack code-bases with what it looks like in .NET Core at:
https://github.com/NetCoreApps/LiveDemos
All .NET Core Live Demos are running on Linux / Docker using AWS ECS Container Service.
We’re maintaining .NET Core packages isolated from the Main NuGet packages separated with a .Core suffix until we’re satisfied .NET Core has been battle-tested in the wild which will enable us to make frequent releases outside of the main .NET 4.5 release cycle.
Please see the full v4.5.2 Release Notes for details on running ServiceStack on .NET Core, its integration story and the different conventions in .NET Core.

Receiving error 'Could not load file or assembly 'Interop.SearchAPI' or one of its dependencies.'

The full message is 'Could not load file or assembly 'Interop.SearchAPI' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.'
After changing some application pools in IIs 7.5 from 2.0 to 4.0 and then back to 2.0 I now receive the above error message. I'm not sure what I need to do to switch the assembly from 4.0 to 2.0.
Thanks for the help!!
Gary
You did not tell us what was your reasons for switching from .NET 4.0 to .NET 2.0.
There are major differences between these runtimes. You can load .NET 2.0 assembly in .NET 4.0 environment but it is not possible to do the other way. If you need to run your application in .NET 2.0 environment then the only option for you is to rebuild all assemblies using .NET 2.0 (or max. .NET 3.5 because the underlying CLR format is the same).
You can read more about .NET versions and compatibility here and here.

Resources