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

[Problem/Bug]: [NET 9] Dependency conflict #4924

Open
hi-xiaoxin opened this issue Nov 14, 2024 · 7 comments
Open

[Problem/Bug]: [NET 9] Dependency conflict #4924

hi-xiaoxin opened this issue Nov 14, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@hi-xiaoxin
Copy link

What happened?

This phenomenon occurred after we upgraded to .NET 9.0, and a warning is generated during compilation:

File: Microsoft.Common.CurrentVersion.targets


发现无法解析的“WindowsBase”的不同版本之间存在冲突。
“WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”与“WindowsBase, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”之间存在冲突。
    已选择“WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”,因为它是主版本而“WindowsBase, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”不是。
    依赖于“WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”[C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\9.0.0\ref\net9.0\WindowsBase.dll]的引用。
        C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\9.0.0\ref\net9.0\WindowsBase.dll
          导致引用“C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\9.0.0\ref\net9.0\WindowsBase.dll”的项目文件项 Include 特性。
            C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\9.0.0\ref/net9.0/WindowsBase.dll
    依赖于或已统一到“WindowsBase, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”[] 的引用。
        C:\Users\user1\.nuget\packages\microsoft.web.webview2\1.0.2895-prerelease\lib_manual\net5.0-windows10.0.17763.0\Microsoft.Web.WebView2.Wpf.dll
          导致引用“C:\Users\user1\.nuget\packages\microsoft.web.webview2\1.0.2895-prerelease\lib_manual\net5.0-windows10.0.17763.0\Microsoft.Web.WebView2.Wpf.dll”的项目文件项 Include 特性。
            C:\Users\user1\.nuget\packages\microsoft.web.webview2\1.0.2895-prerelease\buildTransitive\..\\lib_manual\net5.0-windows10.0.17763.0\Microsoft.Web.WebView2.Wpf.dll

The project does not use WPF or WinForms; it controls windows through the Win32 API (Set Handle). Therefore, there is actually no dependency on WindowBase at all. Previously, everything was normal in the .NET 8.0 environment.

Although the project is still running normally, we would also like to find the cause and eliminate this warning.

Thanks

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime), Prerelease (Edge Canary/Dev/Beta)

Runtime Version

130.0.2849.80

SDK Version

1.0.2895-prerelease

Framework

Other

Operating System

Windows 11

OS Version

22631.4460

Repro steps

Upgrade to .NET 9.0

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@hi-xiaoxin hi-xiaoxin added the bug Something isn't working label Nov 14, 2024
@RalphLAtGitHub
Copy link

The warning also occurs under .NET 8 and only since WebView2 version 1.0.2849.39. The message does not occur in WebView2 version 1.0.2792.45.

@sandeepchads
Copy link

sandeepchads commented Nov 15, 2024

I am wondering whether the issue you're encountering is a version conflict between different versions of the WindowsBase assembly after upgrading to .NET 9.0.

The warning states that WindowsBase, Version=4.0.0.0 was chosen because it is the primary version, while WindowsBase, Version=5.0.0.0 is not. This conflict arises because different parts of your project or its dependencies are referencing different versions of the WindowsBase assembly.

I suspect when upgrading to a new .NET version, some dependencies might still reference older versions of assemblies, leading to conflicts.

Possible Solutions

  1. Binding Redirects:

    • You can add binding redirects in your application's configuration file to resolve the version conflict. This ensures that all references to WindowsBase use the same version.
  2. Update Dependencies:

    • Ensure that all your project's dependencies are compatible with .NET 9.0 and reference the same version of WindowsBase.
  3. Exclude Unnecessary Dependencies:

    • If your project does not use WPF or WinForms, you can try excluding the Microsoft.Web.WebView2.Wpf.dll dependency if it's not needed.

If you need further assistance or have any specific questions, feel free to ask!

@PoulBak
Copy link

PoulBak commented Nov 20, 2024

The problem goes away if you add this to your '.proj' file:

<ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

@RalphLAtGitHub
Copy link

Thanks for the solution! Is there an explanation for this? Thanks!

@PoulBak
Copy link

PoulBak commented Nov 20, 2024

Thanks for the solution! Is there an explanation for this? Thanks!

I don't call this a solution but a temporary workaround until they have fixed their dependency mess. I don't have an explanation (I found this on StackOverflow, don't have the link anymore, sorry).

@UltraWelfare
Copy link

The problem goes away if you add this to your '.proj' file:

<ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

dotnet/msbuild#8289

Downgrading also helps. In the case of a non desktop app (a class library) I'm not sure if it's a sufficient solution.

@sefinek
Copy link

sefinek commented Nov 23, 2024

<ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

I confirm, the warning disappears. Unfortunately, the error still persists. More: dotnet/msbuild#8289 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants