Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImplicitUsings adds usings for both WPF and WinForms if UseWindowsForms is enabled in a WPF project #37608

Open
ivansupport opened this issue Dec 20, 2023 · 3 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@ivansupport
Copy link

ivansupport commented Dec 20, 2023

Problem

The ImplicitUsings property (enabled by default) negatively affects DevExpress customers because our WPF products depend on Windows Forms assemblies. When you create a new WPF project or enable ImplicitUsings in an existing project, the following error occurs because usings for both WPF and Windows Forms are added:

error CS0104: 'Application' is an ambiguous reference between 'System.Windows.Forms.Application' and 'System.Windows.Application'

This issue affects ALL DevExpress WPF customers who either create a new WPF project for .NET or enable ImplicitUsings in an existing project. Our estimate is that more than 50% of WPF customers will be affected by this issue, so we consider it serious/urgent.

You can reproduce the issue as follows:

Approach 1

  • Create a new WPF project for .NET;
  • Enable UseWindowsForms:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
</Project>

Approach 2

  • Create a new WPF project for .NET;
  • Add a reference to a package that enables both WPF and Windows Forms (see ImplicitUsingsTest.zip).

Suggestion

Check the project type in order not to add Windows Forms usings to WPF projects.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Dec 20, 2023
@Alexgoon
Copy link

I'm curious if there are any updates or plans regarding this issue. It's still a serious problem since it disrupts the flow for many new users creating a new WPF project and the workaround is not obvious for them.

@mr-sven
Copy link

mr-sven commented Aug 1, 2024

Found the answer on StackOverflow:

  <ItemGroup>
    <Using Remove="System.Windows.Forms" />
  </ItemGroup>

@modmynitro
Copy link

modmynitro commented Nov 20, 2024

It would be nice if we do not need to use workarounds. UseWpf should work out of the box. The error also occurs if UseWindowsForms is not present.

I am currently setting UseWindowsForms to false to woraround the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants