After upgrading to net5 I'm getting obsoletion warning:
[CS0618] 'HttpRequestMessage.Properties' is obsolete: 'Use Options instead.'
however there seems to be no migration guide.
I.e. there's following code
httpRequestMessage.Properties.Add(Key, Value);
How exactly it should be migrated? Is
httpRequestMessage.Options.Set(new HttpRequestOptionsKey<TValue>(Key), Value);
correct?
I struggled with the same thing and I found the solution. Here is how you should use the new Options property.
Instead of request.Properties.Add("foo", true);
Write: request.Options.Set(new HttpRequestOptionsKey<bool>("foo"), true);
To read the key from response:
response.RequestMessage.Options.TryGetValue(new HttpRequestOptionsKey<bool>("foo"), out bool foo);
To be honest, I don't know why they changed it. It's strange we need to create a new HttpRequestOptionsKey object for each property. But it is what it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With