mono / mono

Mono open source ECMA CLI, C# and .NET implementation.
https://www.mono-project.com
Other
10.93k stars 3.81k forks source link

Visual Studio for Mac Version 8.9 - Error MT2101 System.Security.Cryptography Error #21118

Open rolfbjarne opened 3 years ago

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Mon, 08 Mar 2021 16:11:51 GMT

Steps to Reproduce

  1. Select a physical device (not a simulator)
  2. Build project in either debug or release mode
  3. Build fails with error

Expected Behavior

Should build without errors (previous VS version worked)

Actual Behavior

Build fails with MT2101 error code

Environment

=== Visual Studio Community 2019 for Mac ===

Version 8.9 (build 1651)
Installation UUID: eace7fbf-e085-4d90-8743-cb09e81b53e3
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

    Package version: 612000122

=== Mono Framework MDK ===

Runtime:
    Mono 6.12.0.122 (2020-02/c621c35ffa0) (64-bit)
    Package version: 612000122

=== Roslyn (Language Service) ===

3.9.0-5.21112.8+f3ff04378c972d435826e6181de364b3c0db8d14

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.103/Sdks
SDK Versions:
    5.0.103
    5.0.102
    5.0.101
    5.0.100
    3.1.406
    3.1.405
    3.1.404
    3.1.403
    3.1.402
    3.1.401
    3.1.302
    3.1.301
    3.1.300
    3.1.202
    3.1.200
    3.1.102
    3.1.101
    3.1.100
    3.0.101
    3.0.100
    2.1.701
    2.1.700
    2.1.505
    2.1.302
    2.1.301
    2.1.4
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    5.0.3
    5.0.2
    5.0.1
    5.0.0
    3.1.12
    3.1.11
    3.1.10
    3.1.9
    3.1.8
    3.1.7
    3.1.6
    3.1.5
    3.1.4
    3.1.2
    3.1.1
    3.1.0
    3.0.1
    3.0.0
    2.1.23
    2.1.22
    2.1.21
    2.1.20
    2.1.19
    2.1.18
    2.1.17
    2.1.16
    2.1.15
    2.1.14
    2.1.13
    2.1.12
    2.1.11
    2.1.2

=== .NET Core 3.1 SDK ===

SDK: 3.1.406

=== Xamarin.Profiler ===

'/Applications/Xamarin Profiler.app' not found

=== Updater ===

Version: 11

=== Xamarin Designer ===

Version: 16.9.0.316
Hash: bd2705417
Branch: remotes/origin/d16-9
Build date: 2021-02-24 00:16:08 UTC

=== Xamarin.Android ===

Not Installed

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/Administrator/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:14:56 UTC

=== Android Device Manager ===

Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:15:18 UTC

=== Apple Developer Tools ===

Xcode 12.4 (17801)
Build 12D4e

=== Xamarin.Mac ===

Version: 7.8.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:43-0500

=== Xamarin.iOS ===

Version: 14.14.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:44-0500

=== Build Information ===

Release ID: 809001651
Git revision: c05b1dec4362b5956d47624a437e900ffdc9aa0a
Build date: 2021-02-25 11:27:51-05
Build branch: release-8.9
Xamarin extensions: c05b1dec4362b5956d47624a437e900ffdc9aa0a

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
    Thu Jan 21 00:07:06 PST 2021
    root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

Build Logs

See attached file. BuildLog.txt

Example Project (If Possible)

Not possible, too large.

Copied from original issue xamarin/xamarin-macios#10802

rolfbjarne commented 3 years ago

From @mandel-macaque on Wed, 10 Mar 2021 17:31:01 GMT

Hello, when you say 'not a simulator' does it mean that when you target a simulator the compilation does work. In that case we might be looking at a method that is removed by the linker:

Can't resolve the reference 'System.Void System.Security.Cryptography.DSACng::.ctor(System.Security.Cryptography.CngKey)', referenced from the method 'T Internal.Cryptography.Pal.Windows.PkcsPalWindows::GetPrivateKey(System.Security.Cryptography.X509Certificates.X509Certificate2,System.Boolean,System.Boolean)' in 'System.Security.Cryptography.Cng, Version=4.3.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

If that is the case, can you please use a configuration file to let the linker know that the method should not be removed. You can find how to do it in our documentation.

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 11 Mar 2021 01:40:21 GMT

Yes, that is correct. It builds fine with the simulator but not with a real device. I looked at the linker documentation and I admit that I don't really understand how to create it for this scenario. Any chance you could create it using the build log and post it here? I'd really appreciate it. Thanks.

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 11 Mar 2021 15:04:37 GMT

So I built the App with Linker behavior set to Don't Link and this is the error message I got. Does this help?

/Users/Administrator/Desktop/Development/BlueFire/Xamarin/Motorhomes/Motorhomes/Motorhomes.iOS/MTOUCH: Error MT5216: Native linking failed for '/Users/Administrator/Desktop/Development/BlueFire/Xamarin/Motorhomes/Motorhomes/Motorhomes.iOS/obj/iPhone/Debug/device-builds/iphone7.1-12.5.1/mtouch-cache/arm64/libSystem.Security.Cryptography.Pkcs.dll.dylib'. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new (MT5216) (Motorhomes.iOS)

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 11 Mar 2021 15:28:11 GMT

And if I build with Linker Behavior set to Link All, it builds fine but the App crashes.

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 11 Mar 2021 19:20:02 GMT

I created a Linker.config file and gave it a build action of LinkerDescription. I have no idea how to make the linker file work so I made it like below. This did not solve my problem and I need to get my App built for a critical production release. Is there any way to GO BACK TO VERSION 8.8?

<?xml version="1.0" encoding="UTF-8" ?> <linker> <assembly fullname="BlueFire"> <namespace fullname="System.Security.Cryptography" /> <type fullname="System.Security.Cryptography*" /> <type fullname="System.Security.Cryptography.Pkcs*" /> <type fullname="System.Security.Cryptography.Cng*" /> <type fullname="System.Security.Cryptography.CngKey*" /> <type fullname="System.Security.Cryptography.DSACng*" /> <type fullname="System.Security.Cryptography.X509Certificates*" /> <type fullname="System.Security.Cryptography.X509Certificates.X509Certificate2*" /> </assembly> </linker>

rolfbjarne commented 3 years ago

From @albale221171 on Sat, 13 Mar 2021 13:43:21 GMT

I've the same problem but only in release. In debug it build and I can deploy the app in my iPad. But I can't build the .IPA file for the store. I'm completely blocked! There isn't a workaround?

rolfbjarne commented 3 years ago

From @stefanodelpero on Sat, 13 Mar 2021 17:47:06 GMT

Same thing here, I can't update my app anymore. My app works in simulator and also in debug, but the build release show the same exception. In my case the crypto library that causes the error is in the MailKit library (MimeKit).

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Sun, 14 Mar 2021 17:50:12 GMT

MimeKit uses System.Security.Cryptography.Pkcs so maybe there is a coincidence here. How about it Microsoft. Can you fixe this or give us the ability to go back to version 8.8?

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Wed, 17 Mar 2021 15:02:57 GMT

I have confirmed that, for me, it's MimeKit. I removed all references to it in my code and it builds fine. Not an acceptable solution but at least it is confirmed that it's MimeKit's reference to System.Security.Cryptography.Pkcs that is causing the issue. Note that this worked fine in VS version 8.8 so HOW ABOUT PROVIDING A WAY TO GO BACK TO 8.8?

rolfbjarne commented 3 years ago

From @jstedfast on Thu, 18 Mar 2021 18:35:20 GMT

Can someone link to a VSMac 8.8 build? Then customers can start building & releasing their products while a real fix can be figured out.

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 18 Mar 2021 19:13:59 GMT

I was able to get a 8.8.8 build from Microsoft and installed it however it still failed with the same error. I don't think it matters on a Mac whether you have both builds installed since they are each self contained, right? I've attached the configurations (About VS) for each build. VSMac 8.8.8 Configuration.txt VSMac 8.9.2 Configuration.txt

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Fri, 19 Mar 2021 02:39:58 GMT

I think for now we need to focus on getting the original issue fixed - Error MT2101 System.Security.Cryptography Error. Any updates Microsoft?

rolfbjarne commented 3 years ago

From @jstedfast on Fri, 19 Mar 2021 15:39:22 GMT

AFAIK, they are each self-contained, but perhaps the issue wasn't with the VSMac 8.8 to 8.9 update, but perhaps with a change to Xamarin.iOS or something?

rolfbjarne commented 3 years ago

From @mandel-macaque on Thu, 01 Apr 2021 13:14:29 GMT

I know we had issues with several linking problem, but I have no way to confirm we fixed. Can you please test with: https://bosstoragemirror.blob.core.windows.net/wrench/main/42776ce64de990066618cffdd23806a233b92f2f/4609644/package/xamarin.ios-14.17.0.283.pkg and https://bosstoragemirror.blob.core.windows.net/wrench/main/42776ce64de990066618cffdd23806a233b92f2f/4609644/package/xamarin.mac-7.11.0.283.pkg

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Thu, 01 Apr 2021 15:05:06 GMT

Still same error with Xamain.ios Version: 14.17.0.283. It definitely is related to MailKit. When I revert back to MailKit version 2.6.0 (from 2.11) the error goes away. Mind you the previous VSMac version worked fine with MailKit 2.11.

rolfbjarne commented 3 years ago

From @jstedfast on Tue, 27 Apr 2021 15:16:47 GMT

FWIW, MimeKit's source code has no direct references to RSACng or DSACng, it only ever references the abstract RSA and DSA base classes.

The MimeKit.nuspec and the MimeKit.csproj also do not reference the System.Security.Cryptography.Cng assembly.

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Tue, 27 Apr 2021 16:01:36 GMT

@jstedfast - I believe you're working the issue in this thread, right?

https://github.com/xamarin/xamarin-macios/issues/10802#issuecomment-811899388

rolfbjarne commented 3 years ago

From @jstedfast on Wed, 28 Apr 2021 00:16:40 GMT

I'm assuming they are related, yes.

rolfbjarne commented 3 years ago

From @mandel-macaque on Mon, 03 May 2021 13:54:13 GMT

@jstedfast did you test with the pkgs I linked?

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Mon, 03 May 2021 14:36:39 GMT

@mandel-macaque - Yes, I did and the same error occurred.

rolfbjarne commented 3 years ago

From @jstedfast on Mon, 24 May 2021 18:04:35 GMT

@mandel-macaque what info do you need to reopen this?

I don't understand why the build is failing for @BlueFire-LLC since MimeKit/MailKit do not reference any of the Cng APIs or the nuget packages.

I can't test this myself because I no longer have access to any Macs.

rolfbjarne commented 3 years ago

From @rolfbjarne on Tue, 15 Jun 2021 18:50:53 GMT

MimeKit references System.Security.Cryptography.Pkcs, which references System.Security.Cryptography.Cng:

Loaded assembly 'MimeKit, Version=2.10.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814' from /Users/Administrator/.nuget/packages/MimeKit/2.10.1/lib/netstandard2.1/MimeKit.dll
    References: 'System.Security.Cryptography.Pkcs, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    [...]
Loaded assembly 'System.Security.Cryptography.Pkcs, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' from /Users/Administrator/.nuget/packages/system.security.cryptography.pkcs/4.7.0/runtimes/win/lib/netstandard2.1/System.Security.Cryptography.Pkcs.dll
    References: 'System.Security.Cryptography.Cng, Version=4.3.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    [...]
Loaded assembly 'System.Security.Cryptography.Cng, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' from /Library/Frameworks/Xamarin.iOS.framework/Versions/14.14.2.5/lib/mono/Xamarin.iOS/Facades/System.Security.Cryptography.Cng.dll

Of particular interest is that the System.Security.Cryptography.Pkcs NuGet references System.Security.Cryptography.Cng v4.3.3.0, but gets v4.2.0.0 (from the Facade assemblies we ship, not the NuGet version).

This does not look like a MimeKit bug, but instead either something we're doing wrong (by resolving to the System.Security.Cryptography.Cng we ship), or the System.Security.Cryptography.Pkcs NuGet is doing something wrong.

@marek-safar would you happen to know how this is supposed to work?

rolfbjarne commented 3 years ago

From @rolfbjarne on Tue, 15 Jun 2021 19:23:28 GMT

I can reproduce this by just referencing the System.Security.Cryptography.Pkcs, and passing --linkskip=System.Security.Cryptography.Pkcs to mtouch, no need for MimeKit.

TestApp-c8ee8e4.zip msbuild.binlog.zip

rolfbjarne commented 3 years ago

From @BlueFire-LLC on Tue, 15 Jun 2021 21:56:24 GMT

Thanks for looking into this. I'm still using MimeKit 2.6 where the current is 2.13. Sure will be nice to be able to use the current version.

rolfbjarne commented 3 years ago

From @marek-safar on Fri, 18 Jun 2021 17:05:40 GMT

This is an issue in the Mono implementation of the facade. DSACng type is missing in the facade https://github.com/mono/mono/blob/main/mcs/class/Facades/System.Security.Cryptography.Cng/TypeForwarders.cs#L44

Pluxury commented 2 years ago

Has anyone managed to fix the problem?

jasperkok91 commented 2 years ago

Same issue here anyone solved it without using older version MailKit?

mlancione commented 1 year ago

Any update on this issue or are there any possible workarounds?

mlancione commented 1 year ago

It's been almost 2 years that this issue has been open. Is there a technical challenge in adding the missing facade for DSACng to Mono?