CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

API Confilct

Open Gaoyifei1011 opened this issue 1 year ago • 8 comments

Describe the bug

API Confilct

To Reproduce

When I upgraded to CsWinRT CsWinRT 2.1.0-prerelease.240722.1, I compiled the WinUI 3 project and found that both Microsoft.UI.Colors and Windows.UI.Colors were referenced

ccfd504559f510d2c5727a11b2e43355

Expected behavior

Keep one set of apis

Version Info

CsWinRT 2.1.0-prerelease.240722.1

Additional context

None

Gaoyifei1011 avatar Jul 24 '24 03:07 Gaoyifei1011

This is expected right now. It will be resolved by the time this version is ingested in the .NET SDK as it requires some changes we are making there. For now, you can either use a fully qualified type name or a type alias to workaround it.

manodasanW avatar Jul 24 '24 06:07 manodasanW

Should we make an analyzer to point people to the correct class?

dongle-the-gadget avatar Jul 24 '24 16:07 dongle-the-gadget

I don't think it's worth it, given that:

  • All the Windows.UI.* types will go away as soon as we update the SDK
  • Once we have the updated SDK, if anyone opts-in, WinAppSDK will show a dedicated warning about using "mixed mode", and you'll need to set a separate property manually to override that behavior and make the warning go away.

So in practice once those two updates are in place, the only people hitting this will be expected to know what they're doing 🙂

Sergio0694 avatar Jul 24 '24 22:07 Sergio0694

Will this also resolve my issue with Windows.UI.Text.TextDecorations or should I file a separate issue?

I get this error:

error CS0433: The type 'TextDecorations' exists in both 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b'
 and 'Microsoft.Windows.UI.Xaml, Version=10.0.22621.35, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

So far, I have not been able to resolve this one by fully qualifying the name.

I am using it for this API: https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.documents.textelement.textdecorations

Marv51 avatar Aug 02 '24 14:08 Marv51

@marv51 that's a known issue with some types, but it's only temporary because of a combination of things:

  • You are using an older version of WinAppSDK (if you use 1.6-experimental2, you shouldn't hit this)
  • You are using a preview version of the SDK projections (the next stable release will not have this issue)

So for a temporary workaround, I'd recommend either upgrading WinAppSDK to preview, or downgrading the SDK to latest stable. Alternatively, if you're not using trimming in your project, you should also be able to work around this by temporarily setting CsWinRTRcwFactoryFallbackGeneratorForceOptOut to true in your .csproj file 🙂

Sergio0694 avatar Aug 02 '24 16:08 Sergio0694

This is expected right now. It will be resolved by the time this version is ingested in the .NET SDK as it requires some changes we are making there. For now, you can either use a fully qualified type name or a type alias to workaround it.

I suddenly and unexpectedly found that the WinUI 3 desktop program accidentally loaded Windows.UI.Xaml.dll during debugging 我突然意外的发现,WinUI 3 桌面程序在调试过程中,意外加载了 Windows.UI.Xaml.dll image image

Gaoyifei1011 avatar Aug 06 '24 02:08 Gaoyifei1011

Are you using Windows.UI.Colors? That loads Windows.UI.Xaml.dll.

dongle-the-gadget avatar Aug 06 '24 02:08 dongle-the-gadget

Are you using Windows.UI.Colors? That loads Windows.UI.Xaml.dll.

Yes, I temporarily switched to Windows.ui.colors due to a conflict with the previous Microsoft.ui.colors api

Gaoyifei1011 avatar Aug 06 '24 03:08 Gaoyifei1011