Use .Net Framework class in .Net Core

465 Views Asked by At

Hy Everyone!

I'm developing a .Net Core class library project, but I have to use a class from .Net Framework DLL called System.Security, which is unavailable in Core. (The class is the SignedXml.cs in System.Security.Cryptography.Xml namespace. - Yes I know that namespace and class exists in Core too, but the SignedXml is not the same, there are some private fields which are missing (m_refProcessed, m_refLevelCache etc.).)

I have to use the old class.

Is there any solution to import System.Security in my Core project and extend the SignedXml class? Or just import the SignedXml class?

Thank you!

2

There are 2 best solutions below

1
BernardoPiedade On

I tried to replicate what you want to do, but, it obviously failed, what you could do, is adding a new .net framework solution to the project, and call it when needed, that way you'll be able to use the library you need.

2
JardonS On

If you check in documentation, Microsoft is not describing any differences between the .NET Core and the .NET Framework version.

https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.xml.signedxml?view=netcore-3.1

You should never manipulate private fields, it would be dangerous for the maintainability of your code.

I see that you are talking about an "Old class", when you come to security classes, it's better to stay up to date with latest version. Maybe that the difference is coming from a corrected flaws in the code. It is then a good idea to keep the latest one.

Anyway, .NET Core and .NET framework are not designed to be compatible. On paper, it should be possible when they will release .NET framework 5.0.