In trying to convert the following C# code from a tutorial (by hand, since cross-compilers I have tried don't seem to be able to do this):
httpClient = new HttpClient(unrelated args)
{
DefaultRequestHeaders =
{
Accept = { MediaTypeWithQualityHeaderValue.Parse("text/json") }
}
}
The closest I have been able to get it is:
Dim httpClient As New HttpClient(unrelated args) With
{
.DefaultRequestHeaders [=[New HttpRequestHeaders]] [With]
{
.Accept = {MediaTypeWithQualityHeaderValue.Parse("text/json")
}
}
(where I have tried various combinations of the values in brackets)
No matter what I try, the best I can get is the error
Property
DefaultRequestHeaders
isReadOnly
.
I have confirmed that .DefaultRequestHeaders
and .Accept
are ReadOnly in both VB and C#. Apparently C# is able to write to ReadOnly properties at initialization? Is VB not able to do this as well, or is there some nuance of syntax I am missing to be able to do this? Failing being able to set this at initialization, some other way to set the actual value would presumably work; unfortunately, I don't see a constructor that exposes it, so I don't see any other way to accomplish this, though I would also welcome any suggestion along those lines.