dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.79k stars 193 forks source link

Dotnet 5 Error #458

Closed mateli closed 4 months ago

mateli commented 5 months ago

Create a dotnet 5 WPF project (In VS 2022) Add Vanara.Library 4.0 (3.X works)

An error similar to this occurs: WpfApp2_1zvoyk2w_wpftmp.AssemblyInfo.cs(21, 38): [CS0433] The type 'SupportedOSPlatformAttribute' exists in both 'Vanara.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c37e4080322237fa' and 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

dahall commented 5 months ago

Hm. Doesn't make sense since the compiler directive for that class is:

#if !NET5_0_OR_GREATER

I would make sure you clean the project and the refetch all NuGet assemblies. There is a chance it is using an assembly version for .NET 4.x.

mateli commented 4 months ago

Tried adding the new 4.0.1 to a new dotnet 5 project and got the same error. After locating the nuget directory it has standard 2.0, netcoreapp3.1, net45, net48, netcoreapp3.1, net6, net7, net8.0-windows7.0. Net5 is indeed missing as well as net8.0 non-windows. Is there a 5.0 version built and uploaded to NuGet?

Likewise 3.4.17 doesn't seem to have a net5 build however it does work in net5. I would guess that the fallback is netcoreapp3.1.

I do think that there should be a build for every version of dotnet unless there is a reason to exclude some because of incompatibility problems that can't be fixed.

dahall commented 4 months ago

.NET 5.0 is now deprecated by Microsoft. .NET 8.0 requires the "windows" platform tag for assemblies that use PInvoke and/or COM. This error is resolved if using one of the supported .NET versions.

mateli commented 4 months ago

Yeah I can't tell my customer to move their entire production environment to another framework. This would require a huge amount of testing and certification. Not everyone stop using a framework or product just because Microsoft abandons it.

The solution then is either to include vanara as source in my build or to create a new nuget package targeting more framework versions.

The code to make it work with 5.0 is according to previous posts already there so it's not like fixing this requires digging in to something specific to that version. If it doesn't build that's a different problem.

Sure I would prefer using at least 6.0 for multiple reasons but it's not my call to make.

dahall commented 4 months ago

Let me see if I can make it work for NET 5 and I'll add in the next release.

dahall commented 4 months ago

I have added back .NET 5.0 for the 4.0.2 release coming shortly. You can find the pre-release on AppVeyor (see homepage).

mateli commented 4 months ago

Thanks.