add System.Security.Cryptography.Xml library to .net framework 4.6 project - cryptography

I try to add package via nuget but this error occurs;
Could not install package 'System.Security.Cryptography.Xml 4.4.2'.
You are trying to install this package into a project that targets
'.NETFramework,Version=v4.6', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author.
Ok message is clear but there is a code peace and I moved it to my project. How can I make it work ? it requires this library
public string SignXml(XmlDocument xmlDoc, X509Certificate2 uidCert)
{
try
{
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(xmlDoc);

SignedXml is already available in .NET Framework, you just need to add a reference to System.Security.dll
The NuGet package is for .NET Core, but can be used by .NET Standard (2.0) libraries which run on .NET Core 2.0+ or .NET Framework 4.6.1+. (The .NET Framework implementation just forwards to System.Security.dll).
Alternatively, upgrade your minimum target to 4.6.1 or higher (4.6.1 is 2 and a half years old at this point... and at 4.6 you’re 5 versions out of date).

Related

How do I use a .NET standard 2.0 library with Framework 4.5?

I have found a library that I would like to use in VB.NET with Framework 4.8.
The github says that is is a .NET 4.5 library, but it also says that it is a .NET Standard 2.0 library.
When I when to import it in my VB.NET Framework 4.5 project, it says:
The package "SimpleWifi.netstandard 2.0.0" could not be installed. You are trying to install this package in a project that references ".NETFramework,version=v4.5", but the package does not contain assembly references or content files that are compatible with this framework. Contact the package creator for more information.
What could I try next?
Thank you!
SimpleWifi is said to be used with .NET Fragmework 4.6 or later.
If you want to install in SimpleWifi .net 4.5, change your project to .net 4.8, install SimpleWifi, and then change 4.5 again. However, other errors may occur.

Can't install the Xero.NetStandard.OAuth2

I cannot install the Xero.NetStandard.OAuth2 Nuget package from either VS2017 or VS2019. The error is:
Could not install package 'Xero.NetStandard.OAuth2 3.16.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
While my web app is .NET Framework version 4.6.
The Xero NetStandard SDK targets .NET Standard 2.0 and is only compatible with .NET Framework > 4.6.1.
You can see all the compatible frameworks for .NET Standard 2.0 here:
.NET implementation support

How to access System.Drawing ie System.Drawing.Common in Asp.Net Core 3

I'm in the process of converting an Asp.Net Core 2.2 Website that targeted the Full Framework to an Asp.Net Core 3.1 App that targets .Net Core 3.1. I'm a bit unclear about dependencies related to System.Drawing and how to fulfill them.
My project uses System.Drawing and when compiling under Asp.Net Core 3.1 I get this error that suggests that I add a reference to System.Drawing.Common.dll :
Error CS1069: The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. 1-wwwGiftOasis3 C:\Users\Ron\source\repos\wwwGiftOasis3\wwwGiftOasis3\site\seller\profile\about\s-photos.cs
In Visual Studio I don't see a way to add a reference directly to the bare System.Drawing.Common.dll so I assume that I should add the reference via NuGet.
In NuGet I see a System.Drawing.Common package which looks like what I want but it's unclear to me whether my project fulfills the dependencies:
My Project shows these dependencies:
So I have a couple questions related to all this:
1) Does the fact my the project depends on Framework Microsoft.NETCore.App fulfill the NuGet package's Microsoft.NETCore.Platforms dependency?
2) Does the fact that I intend to only run this Asp.Net Core 3.1 website on windows fulfill the NuGet package's Microsoft.Win32.SystemEvents dependency?
System.Drawing utilizes Windows-specific APIs, and as such, is incompatible with .NET Core, which is cross-platform. Microsoft created System.Drawing.Common as an in-place replacement for System.Drawing for .NET Core. It is an exact API replacement, but performs the image operations in a cross-platform, rather than Windows-specific, way.
Long and short, yes, you just drop the NuGet into your project and go to town. There's nothing else you need to worry about.

System.Web.ApplicationServices in .NET Core 2

I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution
package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.
The app is also throwing this exception below when I call code in one of the custom packages
System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified
Is there any way around this other than re-writing the code in my web Api?
No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.
Long and short, if there's any dependency on System.Web at all, you can't use it.

Using .NET 4.0 library with other dependencies from a .NET 4.5.1 project

I have a .NET project whose target framework is 4.5.1. This project depends on a NuGet library which only has a .NET 4.0 release and this library in turn depends on MVVMLight:
MyProject (4.5.1) --> Depends on MyLibrary (4.0) --> Depends on MVVMLight (4.0)
The MVVMLight NuGet also has a 4.5 version so when it's installed on MyProject it ends up referencing the 4.5 version (as opposed to MyLibrary which was compiled with MVVMLight for .NET 4.0).
This results in the following compilation error:
5>...\Adorners\CircleAdorner.cs(19,18,19,31): error CS0012: The type 'GalaSoft.MvvmLight.ObservableObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'GalaSoft.MvvmLight, Version=4.4.32.18939, Culture=neutral, PublicKeyToken=null'.
The error is from a class CircleAdorner which inherits from a class defined in MyLibrary which in turn inherits from ObservableObject from MVVMLight.
Is this situation "legal"? Is it OK to reference a .NET 4.0 library from a .NET 4.5.1 project? From my understanding it should be OK. However, the catch here is that the .NET 4.0 project expects another dependency which is not satisfied here.
Also, I noticed that the DLL version of GalaSoft.MvvmLight for the .NET 4.5 is 4.4.32.39728 and not 4.4.32.18939. In the project I marked this reference with <SpecificVersion>False</SpecificVersion> but it didn't help.
Yes it is legal for a .NET 4.5.1 project to use a .NET 4.0 assembly. .NET 4.5 is an in place update to .NET 4.0 and is backward compatible.
From NuGet's point of view if the version of project's target framework is less than or equal to the assembly version in the NuGet package then they are considered compatible. So NuGet will allow you to add a NuGet package that targets .NET 4.0 into a project that targets .NET 4.5. What you cannot do is add a NuGet package that only targets .NET 4.5 into a project that targets .NET 4.0 since the assemblies in the NuGet package may use parts of the .NET framework that is not included with .NET 4.0.
When installing a package NuGet will pick the highest version of the .NET framework that the NuGet package contains that is compatible with your project.
With your GalaSoft.MvvmLight version mismatch you should be able to resolve the problem using one of two options:
Update MyLibrary to use the same version of MvvmLight that your project is using.
Add a binding redirect to your project's app.config for GalaSoft.MvvmLight so MyLibrary's reference to it is mapped to the later version. If you are using Visual Studio 2013 and writing a .NET 4.5.1 desktop application you can enable automatic binding redirects instead of updating your app.config.