C# problem with FhirClient

Hello guys.
i write my first c# program for fhir. I installed Fhir.DSTU2.Core v.0.90.4
so there is my code:
var client = new FhirClient(EndPoint);

        HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Reload);
        client.OnBeforeRequest += (object sl, BeforeRequestEventArgs e1) =>
            // Replace with a valid bearer token for the server
            e1.RawRequest.Headers.Add("authorization", "N3 " + miacGuid);
            e1.RawRequest.Headers.Add("LastModified", System.DateTime.Now.ToString("O"));
            e1.RawRequest.CachePolicy = noCachePolicy;
            e1.RawRequest.ContentType = "application/json";
            //      e1.RawRequest.Date = System.DateTime.UtcNow;
            //e1.RawRequest.Headers..Add("content-type", "application/json");

        client.PreferredFormat = ResourceFormat.Json;//xml
        client.UseFormatParam = false;
        client.ReturnFullResource = true;
        client.Timeout = 60000;
            var t=client.Get(EndPoint+"Patient/a6bfef9f-fd80-4c7b-b6c2-5c55ed842e6b");

so a have a problem:

System.ArgumentOutOfRangeException: The Year, Month, and Day parameters describe an unrepresentable DateTime value.

BUT in Fiddler i have

HTTP/1.1 200 OK and get data.

another mistake is

System.Net.ProtocolViolationException: The date string value in the header is not valid.

в System.Net.HttpProtocolUtils.string2date(String S)
BUT in Fiddler i have HTTP/1.1 200 OK and get data.

i think that is something wrong in my preconfig of client or my c#.

Have a look at this stackoveflow discussion which explains the reasons for the System.ArgumentOutOfRangeException exception your are seeing - https://stackoverflow.com/questions/11246563/year-month-and-day-parameters-describe-an-un-representable-datetime-exception

I suspect the second exception is a result of the first one. Once you fix the first one the second should hopefully also go away.

Logging the date that you are trying to use in the header might help you pinpoint the problem.

Thanks for answer, i tried to send header data, but error repeated again.
the mistake is in response, which FHIRClient cant Deserializate it in correct data.

What is the server returning in the header?

"Date →Wed, 09 Jan 2019 19:58:52 GMT

Content-Type →application/json; charset=utf-8

Transfer-Encoding →chunked

Connection →keep-alive

Last-Modified →09.01.19 15:32:02 +00:00

ETag →vecc9445-b315-4abb-a1e1-77df37c2474b

Server →n3.gw


This looks like some form of custom authentication scheme, maybe talk with the server vendor of the FHIR server.

Don’t need to set the contenttype header, as you’re doing a get (and the client will do it for you anyway when it’s needed)
Also not sure why you’re doing the LastModified in the request header. Maybe you’re trying to do http://hl7.org/fhir/http.html#cread

thank you. its just test in header of last-modified parameter, while a sending the request,