Consider the following code:
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace dla.test2{
internal class Test{
public static void Main(){
var map=new Dictionary<string,string>(){
["hello"]="world"
};
using var foo=new FormUrlEncodedContent(map);
}
}
}
Calling the constructor of FormUrlEncodedContent yields the following compiler warning at build-time:
Warning CS8620 Argument of type 'Dictionary<string, string>' cannot be used for parameter 'nameValueCollection' of type 'IEnumerable<KeyValuePair<string?, string?>>' in 'FormUrlEncodedContent.FormUrlEncodedContent(IEnumerable<KeyValuePair<string?, string?>> nameValueCollection)' due to differences in the nullability of reference types.
The documentation for FormUrlEncodedContent indicates the constructor should accept an IEnumerable<KeyValuePair<string,string>>?. My map variable, being a Dictionary<string,string>, would presumably implement the interface IEnumerable<KeyValuePair<string,string>> so I'd expect there to be no problem here. So why the warning?
I'm using Visual Studio 16.8.0 targeting NETCore5.