Error: `principal` must be defined only once in the type namespace of this module

I have a canister which is importing two other canisters using:

#[ic_cdk_macros::import(canister = "environments_db")]
struct EnvironmentsDatabaseCanister;

#[ic_cdk_macros::import(canister = "user_profile_backend")]
struct UserProfileCanister;

In the environments_db canister I’m importing the Principal struct while in user_profile_backend I’m not. However, when I try building the project I get this error:

error[E0428]: the name `principal` is defined multiple times
  --> src/omnia_backend/src/lib.rs:26:1
   |
3  | #[ic_cdk_macros::import(canister = "user_profile_backend")]
   | ----------------------------------------------------------- previous definition of the type `principal` here
...
26 | #[ic_cdk_macros::import(canister = "environments_db")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `principal` redefined here
   |
   = note: `principal` must be defined only once in the type namespace of this module
   = note: this error originates in the attribute macro `ic_cdk_macros::import` (in Nightly builds, run with -Z macro-backtrace for more info)

The only imports that I’m using in both imported canisters are ic_cdk::api::call::ManualReply and candid::CandidType.

Any idea why this is happening?

@chenyan might be able to help. I suggest filing a GitHub issue though.

import doesn’t work at the moment. As a workaround, when you have the did file of the corresponding canister, you can run didc bind user_profile_backend.did -t rs to generate the Rust binding. We plan to integrate this inside cdk, but it’s not done yet.

1 Like

In my case import does work. The problem appears only if I use it twice to import two different canisters.
You mean that I should run the command you suggested just for one of the two canisters while for the other I use import?

“Best practice” in Rust seems to be to just use ic_cdk::api::call::call when doing cross-canister calls. It’s more imperative but just works.

1 Like