hyperledger-archives / aries-framework-dotnet

Aries Framework .NET for building multiplatform SSI services
https://wiki.hyperledger.org/display/aries
Apache License 2.0
84 stars 74 forks source link

AcceptTxnAuthorAgreement results in "Cannot marshal: Encountered unmappable character" #138

Open pstuermlinger opened 4 years ago

pstuermlinger commented 4 years ago

Describe the bug When I try to accept the transaction author agreement it results in an exception.

To Reproduce Use the following Startup.cs service configurations:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging();
            services.AddSingleton<IPoolConfigurator, PoolConfigurator>();

            services.AddAriesFramework(builder =>
            {
                builder.RegisterAgent(options =>
                {
                    options.EndpointUri = "http://localhost:5000";
                    options.AgentName = "My Issuer";

                    options.AgentKeySeed = "000000000000000000000000MYISSUER";
                    options.WalletConfiguration.Id = "IssuerWallet";
                    options.WalletCredentials.Key = "SecretWalletKey";

                    // Available network configurations:
                    //   sovrin-live
                    //   sovrin-staging
                    //   sovrin-builder
                    //   bcovrin-test
                    options.PoolName = "sovrin-builder";
                });
                builder.AcceptTxnAuthorAgreement();
            });

            serviceProvider = services.BuildServiceProvider(true);
        }

Which results into:

System.ArgumentException: Cannot marshal: Encountered unmappable character.
   at System.Runtime.InteropServices.Marshal.StringToAnsiString(String s, Byte* buffer, Int32 bufferLength, Boolean bestFit, Boolean throwOnUnmappableChar)
   at System.StubHelpers.CSTRMarshaler.ConvertToNative(Int32 flags, String strManaged, IntPtr pNativeBuffer)
   at Hyperledger.Indy.NonSecretsApi.NativeMethods.indy_update_wallet_record_value(Int32 command_handle, Int32 wallet_handle, String type_, String id, String value, IndyMethodCompletedDelegate cb)
   at Hyperledger.Indy.NonSecretsApi.NonSecrets.UpdateRecordValueAsync(Wallet wallet, String type, String id, String value)
   at Hyperledger.Aries.Storage.DefaultWalletRecordService.UpdateAsync(Wallet wallet, RecordBase record)
   at Hyperledger.Aries.Configuration.DefaultProvisioningService.AcceptTxnAuthorAgreementAsync(Wallet wallet, IndyTaa txnAuthorAgreement, String acceptanceMechanism)
   at my source file

Expected behavior There shouldn't be an exception.

Desktop:

I stumbled over this issue when I was trying to find the issue of a Ledger operation rejected exception while publishing a schema.

Do you need any more information?

tmarkovski commented 4 years ago

I'll take a look at this. Can you please confirm again the Libindy version? Is is 1.9.0? Can you try updating to anything 1.15? https://repo.sovrin.org/windows/libindy/master/

pstuermlinger commented 3 years ago

Thanks @tmarkovski. I tried it again with Libindy 1.15 but got the same error.

tmarkovski commented 3 years ago

I'm having trouble reproducing this. Is your Windows 10 a 32 or 64 bit? I'm assuming your locale is not en-US. This is not a problem with Aries, but an issue with converting Unicode strings.

https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute.throwonunmappablechar?view=netcore-3.1

We may need to adjust some values in Indy-SDK dotnet wrapper.

pstuermlinger commented 3 years ago

It's a Windows 10 64bit. With locale de-DE. I tried it at a Ubuntu with en-US locale and it indeed worked!

tmarkovski commented 3 years ago

As I suspected. It may be related to Indy SDK wrapper using Ansi as opposed to Unicode in the [DllImport(Charset = Ansi)] https://github.com/hyperledger/indy-sdk/blob/f9eb2cf17b51584f875c4707094256a96656e7b8/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NativeMethods.cs#L12

I'll see if I can reproduce this and see if changing to Unicode will work.

hanlaohan commented 3 years ago

I have the same problem