Closed astryia closed 6 months ago
I'll see if I can repro; however, as a pragmatic workaround for now: maybe just done use the setter, but rather: either use a collection initializer expression, or just access .Endpoints manually and use .Add etc
In other news: I'm wondering if we should mark this setter as [Obsolete]
- and add a separate mechanism. It seems to be causing all manner of pain
I'll see if I can repro; however, as a pragmatic workaround for now: maybe just done use the setter, but rather: either use a collection initializer expression, or just access .Endpoints manually and use .Add etc
You are right, manually initializing collection is a possible workaround.
Another workaround will be making Wrapper project multitarget, so the dependencies sequence will be console-app net8.0 -> wrapper-lib net8.0 -> StackExchange.Redis net6.0 instead of console-app net8.0 -> wrapper-lib netstandard2.0 -> StackExchange.Redis net6.0
But all such workarounds are not intuitive.
I think something should be done on the library level, for example getting rid of this hack
See difference in IL code of the wrapper project: net8.0
IL_0025: dup
IL_0026: ldloc.0 // endPoints
IL_0027: callvirt instance void modreq ([System.Runtime]System.Runtime.CompilerServices.IsExternalInit) [StackExchange.Redis]StackExchange.Redis.ConfigurationOptions::set_EndPoints(class [StackExchange.Redis]StackExchange.Redis.EndPointCollection)
IL_002c: nop
netstandard2.0
IL_0025: dup
IL_0026: ldloc.0 // endPoints
IL_0027: callvirt instance void modreq ([StackExchange.Redis]System.Runtime.CompilerServices.IsExternalInit) [StackExchange.Redis]StackExchange.Redis.ConfigurationOptions::set_EndPoints(class [StackExchange.Redis]StackExchange.Redis.EndPointCollection)
IL_002c: nop
Related issue: https://github.com/dotnet/runtime/issues/96197
Thanks. I'll repro, add the type--forward, and see if that works. Interesting.
Note: we can't simply get rid of "[that] hack" without is being a breaking change; regrets are cheap, sadly. Resolutions: more expensive.
Description
I have netstandard2.0 project which is wrapper around StackExchange.Redis nuget. I have net8.0 console project which is using netstandard2.0 one. I'm getting the following runtime error:
As I understand that the problem is in StackExchange.Redis nuget package which uses init only setters in netstandard version of the library.
Reproduction Steps
CacheWrapper.csproj
CacheWrapper.cs
CacheUser.csproj
Program.cs
This code works if my console application is targeting net48.