Xamarin: Error MT2002: Failed to resolve “System.V

2019-04-20 23:27发布

问题:

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?

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.

回答1:

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).