Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin: Error MT2002: Failed to resolve "System.Void System.Security.Cryptography.SHA1Cng::.ctor()"

I'm getting this error when building my Xamarin solution for iOS.
I have enabled link SDK assemblies only.
Strange thing is, it works just fine when I build it for the simulator, but when I build for a real device it gives this error.

MTOUCH: error MT2002: Failed to resolve "System.Void 
System.Security.Cryptography.SHA1Cng::.ctor()" reference from 
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

No where in my code am I refering to System.Security.Cryptography.

It works when I disable linking assemblies, or enable link all assemblies, but linking all will cause Unity IoC to fail and disable linking all together results in a larger file size for the app.

I'm building for target OS 7.1 (no difference when I change that) for .NET version 4.5.2 and all updates for Xamarin are installed.

Update:
I can confirm that my iOS project is referring to System.Core version 2.0.5.0
See the screenshot below.
However, I do have a PCL project that is referenced. Could that somehow cause the issue?

enter image description here

UPDATE: Turns out there is a library that I was referencing, HashLib, which I thought was a PCL but actually isn't.
Within HashLib there was a call to something in System.Core which caused the linker to fail.
I have now extracted the functionality I needed from HashLib and compiled it into a separate PCL project and this has fixed my linker issue.

like image 944
Ruud van Falier Avatar asked Jul 08 '15 14:07

Ruud van Falier


1 Answers

You're somehow referencing the desktop version of System.Core:

"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

The Xamarin.iOS version has Version=2.0.5.0.

Note that you may not reference this version of System.Core yourself, it can be pulled in indirectly (if you reference an assembly that references System.Core).

Verify that all your references use the 2.0.5.0 version of System.Core (I believe you can use Reflector for this).

like image 152
Rolf Bjarne Kvinge Avatar answered Sep 28 '22 14:09

Rolf Bjarne Kvinge