microsoft / microsoft/CsWinRT

Bug: IReference<TypeName> mapped to Nullable<System.Type> causes compile error

Open
#2,097 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
665
Forks
134
Avg merge
1d 3h
Merged PRs (30d)
32

Description

Description

When generating C# projection from a WinMD that contains a property of type
Windows.Foundation.IReference<Windows.UI.Xaml.Interop.TypeName>,
CsWinRT generates:

public global::System.Nullable<global::System.Type> TargetType { get; set; }
Image This causes a compilation error:

The type 'Type' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

Steps To Reproduce

A minimal IDL to reproduce:

namespace Example
{
    runtimeclass TestClass
    {
        Windows.Foundation.IReference<Windows.UI.Xaml.Interop.TypeName> TargetType;
    }
}

Expected Behavior

CsWinRT should generate the property as:

public global::System.Type TargetType { get; set; }

### Version Info

Microsoft.Windows.CsWinRT 2.2.0

### Additional Context

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WinMD-to-C# projection path using the minimal IDL in the issue, focusing on how IReference<Windows.UI.Xaml.Interop.TypeName> is mapped. Generate the TestClass projection and verify that TargetType is emitted as System.Type rather than Nullable<System.Type>, and that the generated C# compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.