Kobra
Kobra

Reputation: 325

PCLCrypto.dll runtime error

Xamarin, Portable multiplatform solution, portable project section

For MD5 hashing I create class md5. add to project referece PCLCrypto.dll.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PCLCrypto;
using static PCLCrypto.WinRTCrypto;


namespace WCHSBMobile
{
    public static class md5
    {
        public static string GetMD5hash(string data)
        {
            //string result = data;
            IHashAlgorithmProvider algoProv = PCLCrypto.WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5);
            byte[] dataB = Encoding.UTF8.GetBytes(data);
            byte[] dataHash = algoProv.HashData(dataB);
            var hex = new StringBuilder(dataHash.Length * 2);
            foreach (byte b in dataHash)
            {
                hex.AppendFormat("{0:x2}", b);
            }
            return hex.ToString();
            //return result;
        }

    }
}

When testing on android on this line I get Runtime error IHashAlgorithmProvider algoProv = PCLCrypto.WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Md5); I get the error PCLCrypto.NotImplementedByReferenceAssemblyException: This is a reference assembly and does not contain implementation. Be sure to install the PCLCrypto package into your application so the platform implementation assembly will be used at runtime. What should I do? Can you advice me any solution? Thank you

Upvotes: 2

Views: 1942

Answers (3)

Nitin Muteja
Nitin Muteja

Reputation: 1

There seems to be an issue when the package is only installed in the portable class library. The method seems to find the MAC libraries event in Android run which are obviously absent. Hence install it in the PCL and the Android project. The android project libraries will override during the build and you won't have any runtime errors.

Upvotes: 0

Fritz Lim
Fritz Lim

Reputation: 2189

Besides the steps given by J. Andrew Laughlin, what worked for me was to rebuild the app in Xamarin Studio, or clean the app and build it again.

Upvotes: 4

Andrew Laughlin
Andrew Laughlin

Reputation: 2022

I ran into this issue in a Xamarin app. As suggested in the comments by dylan-s and thomas, try the following steps:

  • Uninstall the app
  • Enusure the PCLCrypto Nuget package is installed in the Android project as well as the portable project.

Upvotes: 4

Related Questions