Vanara icon indicating copy to clipboard operation
Vanara copied to clipboard

Dotnet 5 Error

Open mateli opened this issue 10 months ago • 1 comments

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'

mateli avatar Apr 24 '24 15:04 mateli

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.

dahall avatar Apr 27 '24 18:04 dahall

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.

mateli avatar May 24 '24 13:05 mateli

.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.

dahall avatar May 25 '24 01:05 dahall

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.

mateli avatar May 25 '24 10:05 mateli

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

dahall avatar May 25 '24 15:05 dahall

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).

dahall avatar May 26 '24 03:05 dahall

Thanks.

mateli avatar May 26 '24 05:05 mateli