# Deserialize error: binary parser error: Opaque reference not supported at byte offset

**URL:** <https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303>\
**Category:** Developers\
**Tags:** candid\
**Created:** [November 3, 2021, 11:55am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303 "2021-11-03T11:55:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [November 3, 2021, 11:55am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/1 "2021-11-03T11:55:27Z")

</div>

Hi,

Why does the deserialisation fail for the following scenario, where `didc encode` is successful:

Let’s assume the following script, which calls a `method` in Service X. The argument that is passed are serialised by `didc encode` and passed as a `raw` argument via `dfx canister call`.

Here’s how it looks:

```bash
#!/bin/bash

# Test 1: start
# Works!
RECORD="(record {
            \"foobar\";
            variant {
              Id = principal \"$DFX_USER_PRINCIPAL\"
            };
      })"

# Fails! Does not throw error
RAW=$(didc encode "$RECORD")

dfx canister call "$CANISTER_ID" method "$RAW" --type=raw

# Test 1: end

# Test 2: start

# Deserialization error
RECORD="(record {
            \"foobar\";
            variant {
              Id = (25000:nat64)
            };
      })"

# Does not throw error
RAW=$(didc encode "$RECORD")

dfx canister call "$CANISTER_ID" method "$RAW" --type=raw

# Test 2: end

```

---

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [November 3, 2021, 11:58am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/2 "2021-11-03T11:58:14Z")

</div>

When the `raw` is generated in Rust, it works, but not through the didc tool.

```auto
The Replica returned an error: code 5, message: "Canister xxxxx trapped explicitly: Custom(Fail to decode argument 0 from table0 to record

```

```auto
1: Deserialize error: binary parser error: Opaque reference not supported at byte offset 129)

```

Tested with:

```auto
didc 0.1.0

```

Will now update and test again

---

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [November 3, 2021, 12:26pm UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/3 "2021-11-03T12:26:01Z")

</div>

Nope! Latest `didc 0.1.1` does not work either.

Guess would be best to report to the repo at some point, but in case I’m missing something, let know! Thanks

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [November 3, 2021, 4:31pm UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/4 "2021-11-03T16:31:50Z")

</div>

Why are you passing `Id` as `principal` in the first test, and `nat64` in the second test?

Also, if you are writing scripts about canister calls, I recommend you checking out ic-repl ([GitHub - chenyan2002/ic-repl](https://github.com/chenyan2002/ic-repl)).

---

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [November 3, 2021, 5:52pm UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/5 "2021-11-03T17:52:07Z")

</div>

Take it as pseudo-code, to expose the issue, as principal works but not any other type; of course that it reflects the method signature.

I’ll check the ic-repl, wasn’t aware of it.

Thanks!

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [November 3, 2021, 6:50pm UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/6 "2021-11-03T18:50:32Z")

</div>

There is no issue here. The target method expects a principal type. Providing a different type will cause decoding errors.

---

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [November 3, 2021, 7:39pm UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/7 "2021-11-03T19:39:32Z")

</div>

@chenyan the example above was just to highlight the fact that when the target method expects a different type, it fails with the error above, but not when principal.

When:

```auto
source sends principal -> method expects principal works
source sends any other type -> method expects other types fails

```

On the other hand, when the raw data is encoded via rust and passed to the dfx cli, it works.

Works:

```auto
dfx canister call "$CANISTER_ID" method "$RAW_FROM_RUST" --type=raw

```

Fails:

```auto
dfx canister call "$CANISTER_ID" method "$RAW_FROM_DIDC_ENCODE" --type=raw

```

When possible for me, I’ll try to provide a reproducible example

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [November 4, 2021, 12:30am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/8 "2021-11-04T00:30:24Z")

</div>

What does `RAW_FROM_RUST` mean? `didc` is written in Rust and is using the same candid crate. I need a concrete example to understand your problem.

---

<div class="post-metadata">

**Author:** ![anon98822045](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@anon98822045](https://forum.dfinity.org/u/anon98822045)\
**Post date:** [August 22, 2023, 8:32am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/9 "2023-08-22T08:32:45Z")

</div>

Hi there, resurrecting this thread as it seems to be the only result on the interweb for the problem I’m experiencing. Hopefully its something simple.

I have a doubly wrapped Principal. We wrap all the third party types once to standardise things like Display, Serialize, etc. Then we wrap them again inside the ORM so they can benefit from Storable and all the other ORM-specific traits. This allows seamless integration of all types into our ORM so they can be used as keys, values etc.

My issue is that I can’t seem to send this doubly wrapped Principal via the ic\_cdk::call command.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/c/c2f9ea67cec50f39048e60c8cb6f821e0a1e5036.png)

This is calling with the doubly-wrapped type, and returning the newly inserted row.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/4/40128b57212a1873037f0629e19522860534dada.png)

It’s calling init\_player on our Player canister. All the types match up. Here’s the error I’m getting.

```auto
adam@Alien:~/projects/dragginz/backend$ dfx canister call main register_player 'principal "aaaaa-aa"'
(
  variant {
    Err = variant {
      Canister = "IC0503: Canister ahw5u-keaaa-aaaaa-qaaha-cai trapped explicitly: failed to decode call arguments: Custom(Fail to decode argument 0 from principal to principal\n\nCaused by:\n 0: input: 4449444c000168_3f7132706a652d68686e63712d756f6b346c2d616e3577662d73357365362d676e6134322d6a336371752d726b7262362d69616169352d7035376c672d627165\n wire_type: principal, expect_type: principal\n 1: Deserialize error: binary parser error: Opaque reference not supported at byte offset 7) (CanisterError)"
    }
  },
)

```

dont worry about the aaaaa-aa bit, that argument is overridden by the first code block.

This works if I change both the send and receive arguments to just plain Principal.

Here are the debug messages

```auto
2023-08-22 08:26:21.629880878 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] can : ahw5u-keaaa-aaaaa-qaaha-cai
2023-08-22 08:26:21.629880878 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] can dbg : Principal { len: 10, bytes: [128, 0, 0, 0, 0, 16, 0, 14, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
2023-08-22 08:26:21.629880878 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] player : q2pje-hhncq-uok4l-an5wf-s5se6-gna42-j3cqu-rkrb6-iaai5-p57lg-bqe
2023-08-22 08:26:21.629880878 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] player dbg : Principal(Principal(Principal { len: 29, bytes: [237, 20, 40, 229, 113, 96, 111, 108, 89, 118, 68, 241, 154, 14, 105, 59, 20, 41, 21, 68, 62, 64, 0, 142, 191, 191, 89, 131, 2] }))
2023-08-22 08:26:21.629880878 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] args : (Principal(Principal(Principal { len: 29, bytes: [237, 20, 40, 229, 113, 96, 111, 108, 89, 118, 68, 241, 154, 14, 105, 59, 20, 41, 21, 68, 62, 64, 0, 142, 191, 191, 89, 131, 2] })),)

```

---

<div class="post-metadata">

**Author:** ![anon98822045](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@anon98822045](https://forum.dfinity.org/u/anon98822045)\
**Post date:** [August 22, 2023, 9:55am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/10 "2023-08-22T09:55:57Z")

</div>

Actually I think I know what’s going on…

---

<div class="post-metadata">

**Author:** ![anon98822045](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@anon98822045](https://forum.dfinity.org/u/anon98822045)\
**Post date:** [August 22, 2023, 10:04am UTC](https://forum.dfinity.org/t/deserialize-error-binary-parser-error-opaque-reference-not-supported-at-byte-offset/8303/11 "2023-08-22T10:04:02Z")

</div>

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/a/abe1f76b14140b93e83d453facbc387710b09645.png)

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/2/21ca009842fbd7d74a6871a8a4c8e84cd478a442.png)

The issue was PEBKAC. This was really old candid serialization code that I was playing with and I had left in there, was a tough one to figure out.
