Re: Solution Deployment to another environment
I have finally resoled the issue by unpacking the solution zip file and editing manually AppModule.xml file and then repacking, importing back to the solution. The cause looks like a bug in the Microsoft's Power Apps solution management.
Use the following pac command:
# Unpack
pac solution unpack --zipfile yoursolution_1.1.2.59.zip --folder Unpacked\unpacked_1.1.2.59\.
# Repack after edit
pac solution pack --folder Unpacked\unpacked_1.1.2.59\ --zipfile yoursolution_1.1.2.59_repacked.zip
Once unpacked, load the files in Visual Studio (or your favorite editor) and examine AppModule.xml files under AppModule folder. I discovered one of AppElement has missing <canvasAppId> :
<appelement uniquename="..._manageedits_4f5eb">
<canvasappid>
<name>..._manageedits_4f5eb</name>
</canvasappid>
<iscustomizable>1</iscustomizable>
<name>..._manageedits_4f5eb</name>
</appelement>
<appelement uniquename="..._editinitiative_a8ddb">
<iscustomizable>1</iscustomizable>
<name>..._editinitiative_a8ddb</name>
</appelement>
I showed one normal appelement ("..._manageedit") and a broken one ("...editinitiative") above. You can see the second element has missing "<canvasappid><name>..._editinitiative_a8ddb</name></canvasappid>" part. This aligns well with the deployment error message "Value cannot be null. Parameter name: canvasAppReference" too.
I am not sure how this broken element was creeped into my solution but I guess Power Platform did not completely removed all the reference when I deleted an unnecessary custom page (custom pages are considered as "canvas app" in the unpacked xml files). This must be a bug in the platform.
So, what I did was basically, add back the deleted custom page to my solution, exported again, still the <canvasappid> element was missing, manually add them back, repack, re-import, export again, unpack, confirm my edit of <canvasappid> was still there, then pushed to TEST environment again. Voila! it deployed successfully.
Hope this helps. Cheers!