-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a member to an interface breaks compatibility between netstandard2.0 and net6.0 #447
Comments
I have the very similar problem, but with interface IDigest. Then I created console app .Net Core 5.0 and it worked well at least with Standard 2.0 and .Net Core 5.0 libraries. When I used Portable.BouncyCastle 1.9.0 I didn't have such a problem. |
This is also the case for a program targeting net6.0 that references a project targeting netstandard2.1 that in turn references BouncyCastle.Cryptography, although the preprocessor directive states that with |
@fdub is correct - if BouncyCastle were to add a netstandard2.1 target to the nuget packages, this would more-or-less solve the issue. |
There are a number of APIs in BouncyCastle that are conditionally enabled (such as APIs that make use of `ReadOnlySpan<T>`) when `#if NETSTANDARD2_1_OR_GREATER` evaluates to `true`. This causes issues if any library that references BouncyCastle targets netstandard2.1 (and would therefore build against the netstandard2.0 version of BC) is, itself, referenced by an app (or other library) that targets net6.0+, resulting an a "missing implementation" error. Fixes issue bcgit#447 (at least in a practical sense)
Description
When using a project or a package that targets
netstandard2.0
, references BouncyCastle.Cryptography package, and implements some interfaces from BouncyCastle.Cryptography, such as ISigner, in a project that targetsnet6.0
, System.TypeLoadException is thrown with the message: Method does not have an implementation.Reproduction Steps
Visual Studio solution that reproduces the issue: BouncyCastleCryptographyInterfaceIssue.zip
ClassLibrary1.csproj:
ClassLibrary1.MySigner.cs:
ConsoleApp1.csproj:
ConsoleApp1.Program.cs:
Expected behavior
MyAlgorithmName
is output to the Console.Actual behavior
An exception is thrown:
Regression?
Probably yes, after the member Org.BouncyCastle.Crypto.ISigner.BlockUpdate(ReadOnlySpan input) was added and after other conditional compilation members were added to other interfaces.
Known Workarounds
netstandard2.0
andnet6.0
, but that is not possible if a package is coming from a third party.netstandard2.0
by adding the following to the ConsoleApp1.csproj:But this is ugly because users of a third party package must take care of its BouncyCastle.Cryptography package dependency although they are not using the BouncyCastle.Cryptography package directly in their code.
Other information
The issue is happening because there are several interfaces in BouncyCastle.Cryptography package (such as Org.BouncyCastle.Crypto.ISigner that add a member conditionally when targeting
net6.0
, thus changing the interface contract from the compatiblenetstandard2.0
targeted framework.The Change rules for compatibility state:
The solution is to either remove the problematic interface members (conditionally added ones, such as Org.BouncyCastle.Crypto.ISigner.BlockUpdate(ReadOnlySpan input)) (this would be a breaking change of BouncyCastle.Cryptography API) or provide a default implementation for them as explained in the Tutorial: Update interfaces with default interface methods.
For example, the fix for the Org.BouncyCastle.Crypto.ISigner.BlockUpdate(ReadOnlySpan input) would be:
The text was updated successfully, but these errors were encountered: