Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

WinUI3 projects with DisableRuntimeMarshalling=true were getting SYSLIB1051 errors despite the property being set. The XamlPreCompile target runs before CoreCompile but wasn't seeing the SDK-generated DisableRuntimeMarshallingAttribute in the intermediate AssemblyInfo file.

Changes

  • Microsoft.NET.GenerateAssemblyInfo.targets: Added AfterTargets="PrepareForBuild" to ensure GenerateAssemblyInfo runs before XamlPreCompile while maintaining existing BeforeTargets ordering
  • Test coverage: Added test that simulates XamlPreCompile scenario with a custom target depending on GenerateAssemblyInfo
  • Test fixes: Disabled built-in source control integration (EnableSourceControlManagerQueries=false) in tests that expect no source revision ID, as the timing change now picks up Git repository information

Reproduction

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <PublishAot>true</PublishAot>
    <DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
  </PropertyGroup>
</Project>
[Guid("00000000-0000-0000-0000-000000000003")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[GeneratedComInterface]
public partial interface IRepro
{
    void Test(System.Drawing.Point pt);  // Previously failed with SYSLIB1051
}

With this change, the DisableRuntimeMarshallingAttribute is generated early enough for XamlPreCompile to see it.

Original prompt

This section details on the original issue you should resolve

<issue_title>[GeneratedComInterface] Produces SYSLIB1051 in WinUI3 project even though I have DisableRuntimeMarshalling=true</issue_title>
<issue_description>### Description

In a WinUI3 project I get errors telling me that I need to set DisableRuntimeMarshalling but I have done so. And if I add [assembly:DisableRuntimeMarshalling] then I get a "duplicate attribute defined" later during compile.

Reproduction Steps

I pushed a repro up here: https://github.com/jevansaks/WinUI3ComGeneratorsRepro

But the repro is:

  1. File => New Project "WinUI Blank App (Packaged)"
  2. Add this to the csproj:
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <PublishAot>true</PublishAot>
    <DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
  1. Add this to app.xaml.cs:
    [Guid("00000000-0000-0000-0000-000000000003"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GeneratedComInterface]
    public partial interface IRepro
    {
        void Test(global::System.Drawing.Point pt);
    }

Expected behavior

Compiles.

Actual behavior

Gives a confusing error:

App.xaml.cs(33,48,33,50): error SYSLIB1051: Runtime marshalling must be disabled in this project by applying the 'System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute' to the assembly to enable marshalling this type. The generated source will not handle marshalling of parameter 'pt'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1051)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

This seems to be because XamlPreCompile doesn't get all the things passed to it that CoreCompile does. Again. Why does this target exist? :)</issue_description>

<agent_instructions>Update the GenerateAssemblyInfo target so the dependency is the following: AfterTargets="PrepareForBuild"

Then add a test as described in the issue description repro steps.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@jkoritzinsky This is an issue in the XAML integration targets. They aren't pulling in the SDK-generated AssemblyInfo file. Moving to the sdk. @marcpopMSFT Triage: @jlaanstra @Sergio0694 were ya'll going to put up a PR per the suggestion above or looking for someone else to? @marcpopMSFT That is super tricky to test and no testing is really sufficient here. @dsplaisted any suggestions on how to be safe about moving around targets? @dsplaisted If Rainer recommends switching it to PrepareForBuild and it passes our tests, that's probably the best we can do. It would be safer to put a change like that in .NET 11 so that we have a long preview period to hopefully catch any regressions.

It seems like it would be safer to add XamlPreCompile to the BeforeTargets for GenerateAssemblyInfo.

@dsplaisted > If we're touching `XamlPreCompile` again, could we also squeeze in a fix for https://task.ms/57204991 while at it? 😅

That one should be fixed by dotnet/msbuild#12885</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 16, 2025 22:14
…dd test

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
…CompileLikeTarget

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
…o revision ID

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SYSLIB1051 error in WinUI3 project with runtime marshalling Fix GenerateAssemblyInfo timing to support XamlPreCompile targets Dec 16, 2025
Copilot AI requested a review from dsplaisted December 16, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GeneratedComInterface] Produces SYSLIB1051 in WinUI3 project even though I have DisableRuntimeMarshalling=true

2 participants