Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Attempting to JIT compile method #9

Closed
pricimus opened this issue Feb 10, 2015 · 17 comments
Closed

Attempting to JIT compile method #9

pricimus opened this issue Feb 10, 2015 · 17 comments

Comments

@pricimus
Copy link

Hi - I am using your PCLCrypto package to encrypt/decrypt strings in our Android/iOS app. I've defined two simple methods that use the classes and support from the package as follows:

    public string Encrypt(string stringToEncrypt, string cryptoKey)
    {
        byte[] keyMaterial = System.Text.Encoding.UTF8.GetBytes (cryptoKey);
        byte[] data = System.Text.Encoding.UTF8.GetBytes (stringToEncrypt);
        var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
        var key = provider.CreateSymmetricKey (keyMaterial);
        byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key, data);

        return Convert.ToBase64String (cipherText);
    }

    public string Decrypt(string stringToDecrypt, string cryptoKey)
    {
        byte[] keyMaterial = System.Text.Encoding.UTF8.GetBytes (cryptoKey);
        byte[] data = Convert.FromBase64String (stringToDecrypt);
        var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
        var key = provider.CreateSymmetricKey(keyMaterial);
        byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(key, data);

        return System.Text.Encoding.UTF8.GetString(plainText, 0, plainText.Length);
    }

Bu when I run in iOS, I see the following errors:

System.ExecutionEngineException: Attempting to JIT compile method 'CryptoHelper:Decrypt (string,string)' while running with --aot-only

Any ideas?

Thanks,
Ed

@AArnott
Copy link
Owner

AArnott commented Feb 10, 2015

I think Xamarin has a config file where you can explicitly declare methods that their linker fails to anticipate needing. I suggest you follow up with Xamarin support/forums to find out how to do that. I haven't personally hit this problem myself with PCLCrypto but I know this is a classic problem to hit with Xamarin.iOS and I know they have some tricks for you to pull when you hit it to workaround it.

@AArnott AArnott closed this as completed Feb 10, 2015
@pricimus
Copy link
Author

Thanks Andrew - I’ll take a look.

One more problem that I’m getting, running on iOS, is the error "System.NotImplementedException: Not implemented in reference assembly” when trying to do var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7

Do you know what the issue is?

Thanks,
Ed

On 10 Feb 2015, at 17:12, Andrew Arnott notifications@github.com wrote:

I think Xamarin has a config file where you can explicitly declare methods that their linker fails to anticipate needing. I suggest you follow up with Xamarin support/forums to find out how to do that. I haven't personally hit this problem myself with PCLCrypto but I know this is a classic problem to hit with Xamarin.iOS and I know they have some tricks for you to pull when you hit it to workaround it.


Reply to this email directly or view it on GitHub #9 (comment).

@AArnott
Copy link
Owner

AArnott commented Feb 10, 2015

See #10

@AArnott
Copy link
Owner

AArnott commented Feb 10, 2015

That typically happens when you don't install the PclCrypto package into
your iOS app project. If you do that, the problem should go away.

On Tue Feb 10 2015 at 9:16:23 AM pricimus notifications@github.com wrote:

Thanks Andrew - I’ll take a look.

One more problem that I’m getting, running on iOS, is the error
"System.NotImplementedException: Not implemented in reference assembly”
when trying to do var provider =
WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7

Do you know what the issue is?

Thanks,
Ed

On 10 Feb 2015, at 17:12, Andrew Arnott notifications@github.com
wrote:

I think Xamarin has a config file where you can explicitly declare
methods that their linker fails to anticipate needing. I suggest you follow
up with Xamarin support/forums to find out how to do that. I haven't
personally hit this problem myself with PCLCrypto but I know this is a
classic problem to hit with Xamarin.iOS and I know they have some tricks
for you to pull when you hit it to workaround it.


Reply to this email directly or view it on GitHub <
https://github.com/AArnott/PCLCrypto/issues/9#issuecomment-73739956>.


Reply to this email directly or view it on GitHub
#9 (comment).

@hvaughan3
Copy link

@pricimus
Did you ever fix this issue? Just now getting this same problem only when LLVM compiler is turned on.

This issue does not seem to have anything to do with the linker since turning the linker off completely still produces the error if LLVM compiling is turned on.

We have been using PCLCrypto for months successfully up to December 8th (our last push to TestFlight). Now all of a sudden the app crashes on an actual device only when it hits the GetBytes() method while LLVM is turned on.

I am using the latest version of PCLCrypto and the latest version of Xamarin Forms/iOS. Thanks.

I also want to mention this Xamarin Forum thread where other people are experiencing the same issue:
https://forums.xamarin.com/discussion/56990/attempting-to-jit-compile-method-while-running-with-aot-only

@AArnott
Copy link
Owner

AArnott commented Dec 22, 2015

Given the regression you're seeing I suspect the fault is in the Xamarin aot compiler. I don't know how to workaround it.

@hvaughan3
Copy link

Thanks for the info. Will send them an email.

@AArnott
Copy link
Owner

AArnott commented Dec 22, 2015

Please relay anything you learn here for others' benefit. :)

@hvaughan3
Copy link

Will do, speaking with them now.

@qqilihq
Copy link

qqilihq commented Jan 3, 2016

Did you find any solution?

@hvaughan3
Copy link

@qqilihq

Not yet. Emailed Xamarin Support and went back and forth sending them logs and a recreation of the issue. The tech was able to see the error from the demo project I sent but have not heard back from them since before the Xmas break. Will be attempting to contact them again on Monday and will update the thread when I hear something.

@qqilihq
Copy link

qqilihq commented Jan 3, 2016

@hvaughan3 Thank you for the information. Would be really great if you could keep me posted!

@hvaughan3
Copy link

@qqilihq
A public bug report has been filed by Xamarin Support here.

@AArnott
Copy link
Owner

AArnott commented Jan 5, 2016

you can CC yourself on the bug by logging into the bugzilla site and then on the bug page click Save Changes (since the "add me to the CC line" checkbox is checked by default once you're logged in).

@qqilihq
Copy link

qqilihq commented Jan 5, 2016

@hvaughan3 @AArnott Perfect, thank you!

@hvaughan3
Copy link

Thanks @AArnott. It looks like this bug has been fixed, though I have not tested it out yet. Not sure when I will be able to. Thanks for your help.

@hvaughan3
Copy link

@qqilihq
Just wanted to come back to comment about the latest statement in the bug report. Spoke to Xamarin Support again and they are still looking into the issue. They are not sure when it will be fixed but that a solution currently might be to downgrade to version 1.0.2. I have not personally tried this yet though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants