Avoid reflection in CryptoConfigShims #272
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #266
The previous code attempts to invoke an internal method in .NET Core as if it's non-generic, but in recent framework versions it is generic and the invocation fails. This commit replaces the call with a non-reflective call on a public method to avoid similar backwards-breaking changes in the future.
I've tested this code, and it successfully signs a VSTO ClickOnce archive.
Note: There are some special cases handled by the internal method System.Security.Cryptography.Xml.CryptoHelpers.CreateFromName that are not handled by the replacement method,
CryptoConfig.CreateFromName
(they're explicitly listed in a switch inCryptoHelpers.CreateFromKnownName
. However, the only names used inCryptoConfigShims
are forRSAPKCS1SignatureFormatter
andRSAPKCS1SignatureDeformatter
, neither of which appear to be in the list of special cases. So for the purposes ofCryptoConfigShims
, I think the new behaviour is equivalent.