Home > PowerApps > Canvas App Import Failure | CanvasAppEnvironmentMismatch error

Canvas App Import Failure | CanvasAppEnvironmentMismatch error

We configured a new Dynamics Instance copied from another Instance using ‘Customizations and schema only’ option.

While importing a solution with a Canvas App, the solution import failed with CanvasAppEnvironmentMismatch error

CanvasApp import: FAILURE: Code: CanvasAppEnvironmentMismatch Message: The specified app ‘xxx-xx-xxxx-xx’ belongs to the environment ‘xxx-xx-xxxx-xx’ and not ‘xxx-xx-xxxx-xx’ which is the environment associated to instance ‘xxx-xx-xxxx-xx’

Its a strange because, the Instance is a copied one and there were no Canvas Apps exist, when checked in the PowerApps Portal -> Apps tab.

Reason:

  • Even though the PowerApps portal not showing up any Apps, when queried the ‘Canvasapps’ Data Verse entity using oData URL, there were Canvas App records pointing to a different Instance (i.e., The Source Instance which the current instance copied from).
    • Copy the name of the App from json collection. We would need it in next steps.
  • Solution import failed because of the matching Canvas App entry pointing to a different Instance in ‘Canvasapps’ entity.

Fix:

  • Write a C# console and delete the entry in ‘Canvasapps’ entity.
  • Following is the sample code.
 var queryCanvasApps = new QueryExpression("canvasapp")
                {
                    ColumnSet = new ColumnSet(true)
                };

                var filter = new FilterExpression(LogicalOperator.And);
                var cond1 = new ConditionExpression("name", ConditionOperator.Equal, "{App_Name copied in above section}");

                filter.Conditions.Add(cond1);
                queryCanvasApps.Criteria = filter;

                var apps = CrmService.RetrieveMultiple(queryCanvasApps);

                foreach (var app in apps.Entities)
                {
                    //Delete the App entry
                    CrmService.Delete("canvasapp", app.Id);
                }
  • Post deletion, reimport the solution and it should work.

🙂

Advertisement
  1. mwardm
    May 22, 2023 at 5:31 PM

    May 2023.
    Just to say that I was getting a similar error
    ( CanvasApp import: FAILURE: Code: ApplicationIdAlreadyInUse )
    when trying to import into a copied (with data) Dynamics environment.
    Programmatically deleting the record from the canvasapp entity has allowed the import to complete.

    I had already deleted a seemingly related record from the canvasappextendedmetadata entity (which didn’t by itself allow the import to complete), but I tried this deletion first because, unlike the cavnasapp entity, this entity is visible / deleteable through advanced find.
    Cheers.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: