locked
DpiAwareness: Type exists in two assemblies RRS feed

  • Question

  • Hi,

    recent changes in VS2019 introduced DpiAwareness for VS Extensions. However, legacy/WinForms controls won't work out of the box: Currently, those controls are not rendered (they remain blank/transparent). Some info can be found here: Resharper-Blog_DpiAwareness

    There is a proposed solution from Microsoft which sounds fine but doesn't work for me, because I get the error: "The Type DpiAwareness exists in both Microsoft.VisualStudio.DpiAwareness [...] and Microsoft.VisualStudio.Utilities [...]". Both of these references are, however, "part of the BulidSystem" and cannot be removed.

    So how can I resolve this conflict? My project basicall references Microsoft.VisualStudio.SDK and Microsoft.VSSDK.BuildTools.

    Or is there any other way to disable/change/whatever DpiAwareness so that my WinForm ToolWindows will show up again?

    I am also aware of the Option "Optimize rendering for screens with different pixel densities...", but I don't want the customers to change settings to make my windows show...

    Thanks and regards,

    f_max

    Wednesday, September 25, 2019 6:00 AM

Answers

  • Hi again,

    Your comment lead to the solution: I added a manual entry in my project file:

    <Reference Include="Microsoft.VisualStudio.DpiAwareness, Version=6.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <Aliases>foo</Aliases>
    </Reference>

    Now I can add a line right before I instantiate my toolwindow:

    _dpi = foo::Microsoft.VisualStudio.Utilities.DpiAwareness.EnterDpiScope(foo::Microsoft.VisualStudio.Utilities.DpiAwarenessContext.SystemAware);

    Here, _dpi is a member variable which has the same lifetime as the Toolwindow. This actually works, the toolwindows are shown again, and the error I mentioned is gone.

    Thanks,
    f_max


    • Edited by f_max Thursday, September 26, 2019 6:34 PM
    • Marked as answer by f_max Thursday, September 26, 2019 6:36 PM
    Thursday, September 26, 2019 6:32 PM

All replies

  • Hi f_max,

    Welcome to MSDN forum.

    To call specified assembly, we recommend you could use using an external assembly alias to do that:

    #1, set a unique assembly alias in properties window

    #2, add "extern alias [alias]"


    Please refer more about: extern alias (C# Reference)

    Any feedback will be expected.

    Best Regards,

    Dylan



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com




    Thursday, September 26, 2019 6:18 AM
  • Hi Dylan,

    thanks for the response. I found out about aliases as well, but it's not possible because there are no properties at all. See screenshot below (the Microsoft.VisualStudio.SDK reference is selected in the solution explorer). The two assemblies are not listed explicitly as references, they are part of the  "Microsoft.VisualStudio.SDK" Package, and when I select it, the properties remain blank. When I try to add them explicitly, VS tells me that "they are part of the build system" anyway.

    Anyway, I'll try to define an alias directly in the project file (rather than in the properties editor) and check what happens.

    Regards,
    f_max


    • Edited by f_max Thursday, September 26, 2019 7:07 AM
    Thursday, September 26, 2019 7:06 AM
  • Hi again,

    Your comment lead to the solution: I added a manual entry in my project file:

    <Reference Include="Microsoft.VisualStudio.DpiAwareness, Version=6.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <Aliases>foo</Aliases>
    </Reference>

    Now I can add a line right before I instantiate my toolwindow:

    _dpi = foo::Microsoft.VisualStudio.Utilities.DpiAwareness.EnterDpiScope(foo::Microsoft.VisualStudio.Utilities.DpiAwarenessContext.SystemAware);

    Here, _dpi is a member variable which has the same lifetime as the Toolwindow. This actually works, the toolwindows are shown again, and the error I mentioned is gone.

    Thanks,
    f_max


    • Edited by f_max Thursday, September 26, 2019 6:34 PM
    • Marked as answer by f_max Thursday, September 26, 2019 6:36 PM
    Thursday, September 26, 2019 6:32 PM
  • The problem (duplicate type definitions) has been fixed. Just update your nuget packages! You should not need any external aliases anymore. 
    Sunday, April 5, 2020 11:18 AM