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

Do not autoreference WindowsBase.dll in Microsoft.NetCore.App #10378

Closed
AliveDevil opened this issue Jul 15, 2019 · 6 comments
Closed

Do not autoreference WindowsBase.dll in Microsoft.NetCore.App #10378

AliveDevil opened this issue Jul 15, 2019 · 6 comments
Assignees
Milestone

Comments

@AliveDevil
Copy link

Steps to reproduce

  • Create three projects: 2 winforms, 1 shared project
  • Change 1 winform project to net47
  • Create a file in the shared project with namespace System.Windows and try to use System.Drawing.Point
    Like:
namespace System.Windows
{
    using Point = System.Drawing.Point;

    class Repro
    {
        Point point;

        public Repro(Point point)
        {
            this.point = point;
        }
    }
}
  • Reference the shared project from both winforms projects and see what happens.

Expected behavior

This works just fine.

Actual behavior

This works fine on .NET 47, but not on NETCoreApp3.0 due to
dotnet\packs\Microsoft.NETCore.App.Ref\3.0.0-*\data\FrameworkList.xml explicitly referencing WindowsBase:

<File Type="Managed" Path="ref/netcoreapp3.0/WindowsBase.dll" AssemblyName="WindowsBase" PublicKeyToken="31bf3856ad364e35" AssemblyVersion="4.0.0.0" FileVersion="4.700.19.30308" />

In contrast this is the definition for Microsoft.WindowsDesktop.App:

<File Type="Managed" Path="ref/netcoreapp3.0/WindowsBase.dll" AssemblyName="WindowsBase" PublicKeyToken="31bf3856ad364e35" AssemblyVersion="4.0.0.0" FileVersion="4.800.19.30315" Profile="WPF" />

There is an error thrown while compiling that there is a collision between the alias definition of "Point" and the already existing type "Point" inside WindowsBase.

How are we supposed to port our WinForms applications to .NET Core if this is undermined by the .NET Core project?

I've added a minimal repro solution:
winforms.zip

Environment data

.NET Core SDK (gemäß "global.json"):
 Version:   3.0.100-preview6-012264
 Commit:    be3f0c1a03

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\

Host (useful for support):
  Version: 3.0.0-preview6-27804-01
  Commit:  fdf81c6faf

.NET Core SDKs installed:
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.701 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  2.2.301 [C:\Program Files\dotnet\sdk]
  3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
@livarcocc
Copy link
Contributor

@dagood @ericstj since this is about the assemblies factoring in the shared runtimes.

@livarcocc
Copy link
Contributor

Though, wonder if this should have been resolved by the SDK.

cc @nguerrera @dsplaisted as well.

@ericstj
Copy link
Member

ericstj commented Jul 15, 2019

Here's what I'd expect to happen. WindowsBase.dll in Microsoft.NETCore.App is autoreferenced. This never causes an issue since this only has type-forwards for a small subset of the real WindowsBase.dll. WindowsBase.dll in Microsoft.WindowsDesktop.App is only referenced when UseWPF is true and takes precedent over the one in Microsoft.NETCore.App. If this isn't happening it sounds like an SDK issue.

@nguerrera
Copy link
Contributor

I will look at the repro, I expect things to work as @ericstj describes and at least for several cases that I've debugged in the past, this is what I see. Either something regressed or there's a compounding factor in the repro.

@nguerrera nguerrera self-assigned this Jul 15, 2019
@nguerrera
Copy link
Contributor

The repro project is building fine with preview 7, trying preview 6.

@nguerrera
Copy link
Contributor

It does repro with preview 6, the difference being that in preview 6 WindowsBase.dll from Microsoft.WindowsDesktop.App was referenced even when UseWPF=true was not set.

Starting with preview 7, we won't reference WindowsBase.dll by default without UseWPF=true and you can actually compile code like this repro that redefines the meaning of System.Windows.Point. (Strange, by the way, but it will work.)

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 3.0.1xx milestone Jan 31, 2020
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

No branches or pull requests

5 participants