Trying to reference a .NET 4.6.1 class library from a .NET Core project - asp.net

Screenshots => http://imgur.com/a/NWsbh
I'm trying to reference a .NET 4.6.1 Class library in a .NET Core 1.0.0 project. It's added to references but whenever I try to include the "using" statement in a controller I get "the type or namespace could not be found error."
Any suggestions?

You can either only target .NET 4.6.1, and that way you would not support .net core. Or you can add #if NET461 directives in your code, and that way it will be able to find the type and namespace in the if.
your problem is that the code is unsupported in .net core, and therefore cannot build for .net core

You need to set .NET 4.6.1 as the framework for the project. In your project.json, replace the "frameworks"-section with:
"frameworks":
{
"net461": {}
}

Related

ServiceSecurityContext missing in .Net Core (v3.0)

I'm migrating a bunch of .Net Framework 4.6.1 projects into the new .Net Core 3.0 and can't find a nuget packaged that contains the ServiceSecurityContext class.
In .Net Framework the package is located on the System.ServiceModel. Is there a new class that does the same job? Any tips?
CoreWCF has ServiceSecurityContext implemented.
https://github.com/CoreWCF/CoreWCF/blob/b8b33318273cb889bac60b7c8a4c18106e6eb808/src/CoreWCF.Primitives/src/CoreWCF/ServiceSecurityContext.cs
Although, you need to validate if this suites your specific requirements and whether it is interoperable with your .NET Core setup.

How to add .net core dll to an existing .net framework project?

I have a dll target .NET core because of using following library
using Windows.Networking.Sockets;
for creating a UWP App on Windows
Now I would like to import that dll in my currently project which target .net framework in Unity
However add new reference to my .net framework project seem not to work because of incompatibility.
Its possible to convert .net core dll in .net framework ?
I did try to create new .NET framework dll and .NET Standard for trying target both but .net standard and .net framework do not support
using Windows.Networking.Sockets;
Which possible solution do I have now ?
Thanks
You cannot add .Net Core Dll to .Net framework because its not reverse compatible. However you can use a .Net Standard Dll in a .Net Framework project.
Standard is compatible with both Core and Framework.

If the .Net Framework based created dll is supported in the .Net Core Version

I will developed a project in the .Net Framework based 4.5.2 Version using some data base function also.
Oledb Connection
And I will Adding the Class Library in the .Net Core Application Project. The Dll get and accept and build properly in the Application.
But , The Error got the System.Data.Oledb dll is unsupported in runtime .Why ?

.NET Core Class Library with NLog targeting .Net 4.6.1

I'm currently creating a common library from my work that would implement an abstracted logger using NLog.
I've created a .NET Core class library targeting .NET 4.6.1 and implemented NLog, but when I try to execute a unit test that I've created, I've noticed that the nlog.config file is not being picked up. I've also followed the instruction stated https://github.com/NLog/NLog.Extensions.Logging, but I've noticed that it only targets Asp.Net Core and not for .NET Core Class Library solution.
My question is, (given that it is my first time to foray to .NET core) is the instructions stated on the link above applicable for .Net Core class libraries too, or is there a different way to implement this?
Or should I end up not using .Net Core and go for more traditional .NET Class library implementation instead?
Many thanks!
I've created a .NET Core class library targeting .NET 4.6.1 and implemented NLog, but when I try to execute a unit test that I've created, I've noticed that the nlog.config file
It difficult to find the config file when running as unit test. Different frameworks are using different locations. The following options should work
Manually find the config file location as pass it to NLog. Use
LogManager.Configuration = new XmlLoggingConfiguration(filePath, true);
instead of ConfigureNLog() , or
Create a config with the API, or
Create the XML as string and feed it to NLog: instead of ConfigureNLog, use
XElement element = XElement.Parse(configXml);
LogManager.Configuration = new XmlLoggingConfiguration(element.CreateReader(), "nlog.config");
I've noticed that it only targets Asp.Net Core and not for .NET Core Class Library solution.
It works with or without ASP.NET. The ASP.NET parts will be moved to the NLog.Web package in the future

Referencing a .NET Core class library in a ASP.NET 4.6 MVC App

I think that I am fundamentally missing something here and I apologise for stupidity in advance. Trying to embrace the new world of dotnet core and working on a project as a way of trying to learn.
I have written some authentication middleware to work for with ASP.NET Core Identity. I have used a .NET Core Class Library for the middleware - the advantage being that I believe I can then potentially target any framework as well as build Nuget packages of my component. The middleware works fine when used with an ASP.NET Core Web app targetting .NET Core - based on the VS2015 RC2 template.
Feeling adventurous I decided to create a version of the component based around OWIN/Katana authentication middleware so I could use it with ASP.NET 4.5/6 web applications. Instead of creating a traditional class library project I once again used the .NET Core Class Library template but targetted it only at .NET 4.6, i.e. net46. It compiles fine but I cannot get my ASP.NET 4.6 application to reference it. I followed the information in this SO question to create a NuGet package, create a local source and then try to add it to my ASP.NET 4.6 project but it fails with the error:
Unable to resolve dependency 'NETStandard.Library'. Source(s) used: 'nuget.org', 'AspNetRc2Source', 'MyGet', 'Local', 'Microsoft and .NET', 'Microsoft Visual Studio Offline Packages'. 0
My head is spinning with dependencies and frameworks.
Anyway here is the project.json file in my .NET Core class library - you can see it is only targeting .NET 4.6 which is what my ASP.NET app is targeting too.
I feel I need some serious .NET 101 course to get my head around how all these dependencies fit together, but if anyone is kind enough to point me in the right direction it would be appreciated.
Remove the reference to NETStandard.Library and it should work. You don't need that if you're only targeting .NET 4.5+.
I work on an OWIN middleware library that can be consumed from both .NET 4.5+ and .NET Core. I target both using a project.json that looks like this:
"dependencies": {
"Stormpath.Owin.Abstractions": {
"target": "project",
"version": "1.0.0"
}
},
"frameworks": {
"net45": {
"frameworkAssemblies": {
"System.Collections": "4.0.0.0"
}
},
"netstandard1.3": {
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
}
}
}
Since only .NET Core (netstandardX.Y) requires .NETStandard.Library, it's listed as a dependency for only that target, not as a general dependency. The project will happily build for .NET 4.5 and dotnet pack produces libraries that install perfectly on both platforms.

Resources