Skip to content

Win2D with Xaml Islands Problem #999

@rmarinho

Description

@rmarinho

When I try a real world app (legacy wpf app ported to net8.0-windows) it works fine with WinUI and Xaml Islands but as soon as I try to use a Win2D like create CanvasControl (this is via .NET MAUI) it fails with following error.

System.Runtime.InteropServices.COMException (0x80040154): The data area passed to a system call is too small.

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at WinRT.ActivationFactory.Get(String typeName, Guid iid)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet.get__objRef_global__Microsoft_Graphics_Canvas_Text_ICanvasFontSetFactory()
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
Image

hard for me to share a repo as in my sample works fine.

One of the differences is on real world app uses a plugin model where we don t add reference to a Lib project like in the sample app, it loads the assembly and creates the control. But like I said above works fine with Xaml Islands, so the init of the WindowsAppSdk seems to be working fine

Example of the csproj

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>WinExe</OutputType>
   		<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
    		<TargetName>Studio</TargetName>
		<StartupObject>iStudio.Program</StartupObject>
		<NeutralLanguage>en</NeutralLanguage>
		<UseWindowsForms>true</UseWindowsForms>
    		<UseWpf>true</UseWpf>
    		<UseWinUI>true</UseWinUI>
    		<LangVersion>default</LangVersion>
		<UseApplicationTrust>false</UseApplicationTrust>
		<Nullable>enable</Nullable>
		<ImplicitUsings>disable</ImplicitUsings>
		<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
		<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
		<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
		<SignAssembly>True</SignAssembly>
		<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
		<EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
		<GenerateDependencyFile>false</GenerateDependencyFile>
		<RollForward>LatestMinor</RollForward>
    		<WindowsAppSdkBootstrapInitialize>true</WindowsAppSdkBootstrapInitialize>
   		<WindowsPackageType>None</WindowsPackageType>
    		<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  	</PropertyGroup>

  	<ItemGroup>
    		<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250606001" />
    		<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4188" />
  	</ItemGroup>

  <ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
    <PackageReference Include="Microsoft.Graphics.Win2D" Version="1.3.2" />
    <PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
  </ItemGroup>
  
  <PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net8.0'))">
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <UseRidGraph>true</UseRidGraph>
  </PropertyGroup>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions