Closed donaghy closed 8 months ago
@rolfbjarne Is this something that can be addressed by us? This seems like something at the library level to keep it from being trimmed, or maybe it should't be trimmed at all? I'm not sure if this is a bug.
@donaghy can you post the full stack trace of the exception?
Hi @donaghy. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I've added the stacktrace detail, there is very little to it. Note that we found a workaround by excluding the assembly 'System.Secruity.Cryptography' from the linker. As the Android release build works with the linker process would this indicate that the Assembly is correctly marked as 'Trimmable' were applicable and the issue lays with the iOS Linker? I'm assuming also though that part of that assembly may be platform specific and not have the correct Trimmable attributes where necessary.
This is an issue with the PCLCrypto library, it's not trimmer-safe.
Referencing it in a net8.0-ios project yields this build warning:
warning NU1701: Package 'PCLCrypto 2.0.147' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0-ios17.2'. This package may not be fully compatible with your project.
Looking at the compatible frameworks here: https://www.nuget.org/packages/PCLCrypto/2.1.40-alpha#supportedframeworks-body-tab
We can deduce that it has a specific implementation for Xamarin.iOS (because "xamarinios10" is darker blue), but it does not have a specific implementation for net8.0-ios (because "net8.0-ios" is a lighter blue).
Looking at the source code, there's an iOS-specific block:
but since there's no iOS-specific version of the NuGet for .NET, that code path won't be hit, so this is executed:
which is probably not trimmer safe.
Thanks for investigating the issue and the detailed explanation. Much appreciated.
Description
When building a MAUI project targeting iOS with MtouchLink = SdkOnly we are seeing the error "Speficied method is not supported" for the execution of PCLCrypto.SymmetricKeyAlgorithmProvider.GetAlgorithm(). When we set the MtouchLink option to None it works fine.
We dont see this issue in our Android release builds of the same project.
Steps to Reproduce
`byte[] keyMaterial = [method to generate key bytes];
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7); var key = provider.CreateSymmetricKey(keyMaterial);`
Link to public reproduction project repository
No response
Version with bug
8.0.6 SR1
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 17.0.2
Adding assembly 'System.Secruity.Cryptography' as a TrimmerRootAssembly appears to resolve the issue.
Relevant log output
Message -> "Specified method is not supported." Stacktrace -> "at PCLCrypto.SymmetricKeyAlgorithmProvider.GetAlgorithm() at PCLCryptto.SymmeticKeyAlogorithmProvider.CreateSymmetricKey(Byte[] keyMatrial) at {line of code being excuted}