Xamarin.UWP: Release build failed when solution has many class and generic types

Volcano 56 Reputation points
2021-08-15T17:04:45.697+00:00

I have two solutions base on the same framework, has the same NuGet packages, and all can run in debug model and be release to android. The bigger one failed on release build, but the other one build success.

The build log shows:

83>"D:\MyApp\MyApp.UWP.csproj" (_GenerateAppxPackage target) (1) ->  
83>(BuildNativePackage target) ->   
83>  C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.10-rel-29722-00\tools\Microsoft.NetNative.targets(805,5): error : RHBIND : error RHB0002: Failed to write PDB.  
83>  C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.10-rel-29722-00\tools\Microsoft.NetNative.targets(805,5): error : ILT0005: 'C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\tools\x86\ilc\Tools\rhbind.exe @"D:\MyApp\obj\x86\Release\ilc\intermediate\rhbindargs.MyApp.UWP.rsp"' returned exit code 2  

After I add <NetNativeReproPath>D:\myRepro</NetNativeReproPath> accroding to .NET Native Internal Compiler Errors, error message in build log changed:

83>"D:\MyApp\MyApp.UWP.csproj" (_GenerateAppxPackage target) (1) ->  
83>(_GenerateAppxPackageRecipeFile target) ->   
83>  D:\MyApp\Package.appxmanifest : error APPX0703: Manifest references file 'Microsoft.Graphics.Canvas.dll' which is not part of the payload.  
83>  D:\MyApp\Package.appxmanifest : error APPX0703: Manifest references file 'MyApp.UWP.exe' which is not part of the payload.  

Error: Manifest references file xxxxx.dll which is not part of the payload said should add "Microsoft Visual C++ 2013 Runtime Package for Windows". "Visual C++ 2015-2019 Runtime for Universal Windows Platform Apps" already existed in this solution, and after added "Microsoft Visual C++ 2013 Runtime Package for Windows Universal", "Visual C++ 2015-2019 UWP Desktop Runtime for native apps", the same error still existed.

Question:

  1. If this error is caused by any NuGet package, why the smaller size one can make a success release build?
  2. After I removed all NuGet packages with placeholder except Xamarin.Essentials(Version="1.7.0") and Xamarin.Forms(Version="5.0.0.2083"), the release build still failed. Is this the .NET Native Compiler Errors?
  3. How could I add 'Microsoft.Graphics.Canvas.dll' for x86, x64 and arm which should be released in Microsoft Store?
  4. Why the error log changed after add <NetNativeReproPath>D:\myRepro</NetNativeReproPath>? The default build log is supposed to be clear enough.

Visual studio:Version 16.11.0
UWP Target version: Windows 10, version 2004(build 19041)

More: Aug 15, 2021

I searched all files in the solution direction to find which contains "Microsoft.Graphics.Canvas", I found many files contains it actually. this is the result:

D:\MyApp.UWP\AppPackages\MyApp.UWP_1.0.1.0_Test\MyApp.UWP_1.0.1.0_x86.appxbundle  
D:\MyApp.UWP\bin\x86\Release\AppxManifest.xml  
D:\MyApp.UWP\bin\x86\Release\MyApp.UWP.build.appxrecipe  
D:\MyApp.UWP\bin\x86\Release\MyApp.UWP_1.0.1.0_x86.appx  
D:\MyApp.UWP\bin\x86\Release\Microsoft.Graphics.Canvas.dll  
D:\MyApp.UWP\bin\x86\Release\Microsoft.Graphics.Canvas.winmd  
D:\MyApp.UWP\bin\x86\Release\SignaturePad.dll  
D:\MyApp.UWP\bin\x86\Release\Xamarin.Forms.Platform.UAP.dll  
D:\MyApp.UWP\bin\x86\Release\Xamarin.Forms.Platform.UAP.pdb  
D:\MyApp.UWP\bin\x86\Release\ZXing.Net.Mobile.Forms.pdb  
D:\MyApp.UWP\bin\x86\Release\ilc\Data.g.cs  
D:\MyApp.UWP\bin\x86\Release\ilc\Helpers.g.cs  
D:\MyApp.UWP\bin\x86\Release\ilc\ImplTypes.g.cs  
D:\MyApp.UWP\bin\x86\Release\ilc\SafeTypes.g.cs  
D:\MyApp.UWP\bin\x86\Release\ilc\SharedStubs.g.cs  
D:\MyApp.UWP\obj\project.assets.json  
D:\MyApp.UWP\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache  
D:\MyApp.UWP\obj\x86\Release\MyApp.UWP.csproj.AssemblyReference.cache  
D:\MyApp.UWP\obj\x86\Release\MyApp.UWP.csproj.FileListAbsolute.txt  
D:\MyApp.UWP\obj\x86\Release\filemap.map.txt  
D:\MyApp.UWP\obj\x86\Release\filemap.pri  
D:\MyApp.UWP\obj\x86\Release\filemap.scale-100.pri  
D:\MyApp.UWP\obj\x86\Release\filemap.scale-400.pri  
D:\MyApp.UWP\obj\x86\Release\main.map.txt  
D:\MyApp.UWP\obj\x86\Release\.winmd_cache\$Microsoft.Graphics.Canvas.winmd_636340429040000000.json  
D:\MyApp.UWP\obj\x86\Release\MyApp.UWP_1.0.1.0_Bundle\MyApp.UWP_1.0.1.0_x86.appx  
D:\MyApp.UWP\obj\x86\Release\ilc\in\AppxManifest.xml  
D:\MyApp.UWP\obj\x86\Release\ilc\in\Microsoft.Graphics.Canvas.dll  
D:\MyApp.UWP\obj\x86\Release\ilc\in\Microsoft.Graphics.Canvas.winmd  
D:\MyApp.UWP\obj\x86\Release\ilc\in\SignaturePad.dll  
D:\MyApp.UWP\obj\x86\Release\ilc\in\Xamarin.Forms.Platform.UAP.dll  
D:\MyApp.UWP\obj\x86\Release\ilc\in\Xamarin.Forms.Platform.UAP.pdb  
D:\MyApp.UWP\obj\x86\Release\ilc\in\ZXing.Net.Mobile.Forms.pdb  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop.dll  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop.pdb  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\gkargs.rsp  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\Native.res  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\BuildInfo\BuildInfo.res  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\BuildInfo\BuildInfo.txt  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop\Data.g.cs  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop\Helpers.g.cs  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop\ImplTypes.g.cs  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop\SafeTypes.g.cs  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MyApp.UWP.McgInterop\SharedStubs.g.cs  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\MyApp.UWP.ilexe.ILTransformTask.repro  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\MyApp.UWP.McgInterop.ildll  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\MyApp.UWP.McgInterop.ilpdb  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\MyApp.UWP.metadata  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\MyApp.UWP.reflectionlog.csv  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\SignaturePad.ildll  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\System.Private.MyApp.UWP.Generated.ildll  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\Xamarin.Forms.Platform.UAP.ildll  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\ILTransformed\Xamarin.Forms.Platform.UAP.ilpdb  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\MDIL\MyApp.UWP.mdilexe  
D:\MyApp.UWP\obj\x86\Release\ilc\intermediate\Native\MyApp.UWP.dll  
D:\MyApp.UWP\obj\x86\Release\PackageLayout\MyApp.UWP.dll  
D:\MyApp.UWP\obj\x86\Release\PackageLayout\MyApp.UWP.exe  
D:\MyApp.UWP\obj\x86\Release\PackageLayout\Microsoft.Graphics.Canvas.dll  
D:\MyApp.UWP\obj\x86\Release\PackageLayout\Microsoft.Graphics.Canvas.winmd  

And in file D:\MyApp.UWP\obj\project.assets.json, it contains:

  "Xamarin.Forms/5.0.0.2083": {  
    "type": "package",  
    "dependencies": {  
      "Microsoft.UI.Xaml": "2.4.3",  
      "Win2D.uwp": "1.20.0"  
    },  
   ...  
  "Win2D.uwp/1.21.0": {  
    "type": "package",  
    "compile": {  
      "lib/uap10.0/Microsoft.Graphics.Canvas.winmd": {}  
    },  
    "runtime": {  
      "lib/uap10.0/Microsoft.Graphics.Canvas.winmd": {}  
    },  
    "native": {  
      "runtimes/win10-arm/native/Microsoft.Graphics.Canvas.dll": {}  
    }  
  },  

Also, I found Win2D.uwp is a NuGet package, which contains Microsoft.Graphics.Canvas.dll, and has x64, x86, Arm versions.

So, more questions:

  1. If Microsoft.Graphics.Canvas.dll is a valid part of Win2D.uwp, why 'Microsoft.Graphics.Canvas.dll' is not part of the payload?
  2. Does this error is caused by wrong setting in csproj file (example as below)? <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>false</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>false</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
    <Use64BitCompiler>true</Use64BitCompiler>
    <SingleThreadNUTC>true</SingleThreadNUTC>
    <ShortcutGenericAnalysis>true</ShortcutGenericAnalysis>
    <UseDotNetNativeSharedAssemblyFrameworkPackage>false</UseDotNetNativeSharedAssemblyFrameworkPackage>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    </PropertyGroup>

More: Aug 17, 2021

According to the tips from web, I added 'Microsoft.Graphics.Canvas.dll' and 'MyApp.UWP.exe' to csproj file manually:

<ItemGroup>  
  <AppxSystemBinary Include="Microsoft.Graphics.Canvas.dll"/>  
  <AppxSystemBinary Include="DIKA.InspectAid.UWP.exe"/>  
</ItemGroup>  

The release error changed to "Target obj\x86\Release\PackageLayout does not exist"

83>_GenerateAppxPackageRecipeFile:  
83>  MyApp.UWP -> D:\MyApp\MyApp.UWP\bin\x86\Release\MyApp.UWP.build.appxrecipe  
83>_CreatePackageLayout:  
83>  Directory "obj\x86\Release\PackageLayout\" doesn't exist. Skipping.  
83>  MyApp.UWP -> obj\x86\Release\PackageLayout\  
83>_SplitResourcesPri:  
83>  C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\MakePri.exe New -ProjectRoot obj\x86\Release\PackageLayout\ -ConfigXml obj\x86\Release\split.priconfig.xml -OutputFile obj\x86\Release\split.pri -IndexName 3B3C62F3.5494505C4A71E -MappingFile AppX -Verbose -Overwrite    
83>GENERATEPROJECTPRIFILE : error : PRI180: 0x80070057 - Target obj\x86\Release\PackageLayout does not exist  
83>GENERATEPROJECTPRIFILE : error : PRI193: 0x80070057 - Please provide a valid Project Root  

Question:

  1. Why directory "obj\x86\Release\PackageLayout" not be created?

More: Aug 18, 2021

I found the compilation process is different compare to a successful one: After every single project has complied and every file has been copy to “obj\x86\Release\ilc\in” successfully, The .NET Native compilation can not started, many process has been missed(see below).

Build log from success solution:

77>Done executing task "IlcMessageTask".  
77>Task "WriteLinesToFile"  
77>Done executing task "WriteLinesToFile".  
77>Using "LoggerBasedExecTask" task from assembly "C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\build\..\tools\x86\ilc\tools\Microsoft.Build.ILTasks.dll".  
77>Task "LoggerBasedExecTask"  
77>  C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\build\..\tools\\x86\ilc\ilc.exe @"obj\x86\Release\ilc.MyAPP.UWP.rsp" "/logger:CsvLogger;4936;2680"   

(start of missed)

77>  Starting .NET Native compilation  
77>    
77>  Task "Gatekeeper"  
77>  Done executing task "Gatekeeper".  
77>  Done building target "RunGatekeeper" in file "Preparation".  
77>    
77>  Done building target "CreateToolchainGeneratedAssembly" in file "Preparation".  
77>    
77>  Task "PreMergeAssemblyClosure"  
77>  Done executing task "PreMergeAssemblyClosure".  
77>  Done building target "ConstructPreMergeAssemblyClosure" in file "Preparation".  
77>    
77>  Task "McgReferenceResolveFilePath"  
77>  Done executing task "McgReferenceResolveFilePath".  
77>  Done building target "PreResolveTransforms" in file "Preparation".  
77>    
77>  Task "ResolveToolchainRequiredAssemblyRoots"  
77>  Done executing task "ResolveToolchainRequiredAssemblyRoots".  
77>  Task "ILTransformAssemblyClosure"  
77>  Done executing task "ILTransformAssemblyClosure".  
77>  Task "ResolveToolchainRequiredAssemblyRoots"  
77>  Done executing task "ResolveToolchainRequiredAssemblyRoots".  
77>  Task "ReducedCopyAssemblyClosure"  
77>  Done executing task "ReducedCopyAssemblyClosure".  
77>  Done building target "ConstructILTransformAssemblyClosure" in file "Preparation".  
77>  Done building project "Preparation".  
77>    
77>    
77>  Processing application code  
77>  Task "RunILTransforms"  
77>  Done executing task "RunILTransforms".  
77>  Done building target "RunILTransforms" in file "ILTransforms".  
77>  Done building project "ILTransforms".  
77>    
77>    
77>  Done building target "GenerateMDIL" in file "Nutc".  
77>    
77>  Generating native code  
77>  Done building target "MDILPrepareMultiFile" in file "Nutc".  
77>    
77>  Done building target "SetBinaryForReferences" in file "Nutc".  
77>    
77>  Task "GenerateMDILGlobalAnalysis"  
77>  Done executing task "GenerateMDILGlobalAnalysis".  
77>  Done building target "GenerateMDILGlobalAnalysis" in file "Nutc".  
77>  Done executing task "ResourceBinaryConcatenate".  
77>  Done building target "GenerateBuildInfo" in file "Nutc".  
77>  Done building project "Nutc".  
77>    
77>    
77>  Done building target "MDILBindPrepare" in file "Binder".  
77>    
77>  Generating fixups for native code  
77>  Done executing task "MDILBind".  
77>  Done building target "MDILBind" in file "Binder".  
77>  Done building project "Binder".  
77>    
77>  Done building target "CopyNativeExecutablesToOutput" in file "Deployment".  
77>    
77>  Task "TransformAppxManifest"  
77>  Done executing task "TransformAppxManifest".  
77>  Done building target "TransformAppxManifestAndAddCrt" in file "Deployment".  
77>    
77>  Done building target "CopyPackageResourceFileInRetailBuild" in file "Deployment".  
77>  Done building project "Deployment".  
77>  Compilation finished  
77>  Compilation successful.  

(end of missed)

77>    
77>Done executing task "LoggerBasedExecTask".  

Build log from failed solution:

70>Done executing task "IlcMessageTask".  
70>Task "WriteLinesToFile"  
70>Done executing task "WriteLinesToFile".  
70>Using "LoggerBasedExecTask" task from assembly "C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\build\..\tools\x86\ilc\tools\Microsoft.Build.ILTasks.dll".  
70>Task "LoggerBasedExecTask"  
70>  C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-x86.microsoft.net.native.compiler\2.2.10-rel-29722-00\build\..\tools\\x86\ilc\ilc.exe @"obj\x86\Release\ilc.DIKA.InspectAid.UWP.rsp" "/logger:CsvLogger;3136;4120"   
70>    
70>Done executing task "LoggerBasedExecTask".  

Qusetion:

  1. Why .NET Native compilation can not started?
  2. Does this has any relation to 'Microsoft.Graphics.Canvas.dll' is not part of the payload?

More: Aug 19, 2021

“'Microsoft.Graphics.Canvas.dll' and 'MyApp.UWP.exe' is not part of the payload” is caused by add <NetNativeReproPath>D:\myRepro</NetNativeReproPath> to csproj. If you add <NetNativeReproPath>D:\myRepro</NetNativeReproPath> to any Xamarin.UWP project, you will get this error when make a release build. And more, you will get "Target obj\x86\Release\PackageLayout does not exist" and .NET Native compilation can not started.

I'm pretty sure the build fail is caused by Native complier, for:

  1. With the same NuGet packages, The smaller (has less class and generic type) solution will compile success, and the same time the complex one will fail;
  2. If I remove all NuGet packages, release build still failed;

It's really upset to deal with Xamarin.UWP for recently two years, and you can hardly find resource and help.

Universal Windows Platform (UWP)
{count} vote