CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

CopyBuffer() method of SoftwareBitmap to an array crashes when trimming is enabled

Open lhak opened this issue 3 years ago • 1 comments

Describe the bug

When using the CopyBuffer() method of a SoftwareBitmap to copy the pixels to a byte array the app crashes with an "Invalid cast" exception if trimming is enabled

To Reproduce

  1. Run attached repro project

SoftwareBitmapTrimRepro.zip

Expected behavior

Should work the same as without trimming enabled

Version Info

WindowsAppSDK 1.2

Additional context

lhak avatar Nov 14 '22 17:11 lhak

It seems that the issue is caused by the WindowsRuntimeBuffer class (and related extension methods like AsBuffer() for arrays) when trimming is enabled. Workaround: Add a TrimmerRootDescriptor file with the following content:

<linker>
  <assembly fullname="Microsoft.Windows.SDK.NET">
    <type fullname="System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBuffer"/>
  </assembly>
</linker>

lhak avatar Dec 30 '22 22:12 lhak