Index: Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs +++ b/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs @@ -1144,6 +1144,14 @@ Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0)); Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(1)); Assert.That(httpRequest.Headers.IfMatch.First(), Is.EqualTo(new EntityTagHeaderValue(body.ETag))); + + // Fixing bug https://code.google.com/p/google-api-dotnet-client/issues/detail?id=464. + // If etag doesn't contain quotas - catch the format exception and log. + body.ETag = "ETAG"; + request = new TestClientServiceRequest(service, HttpConsts.Post, body); + httpRequest = request.CreateRequest(); + Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0)); + Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(0)); } } Index: Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs =================================================================== --- a/Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs +++ b/Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs @@ -185,7 +185,6 @@ object body = GetBody(); request.SetRequestSerailizedContent(service, body, overrideGZipEnabled.HasValue ? overrideGZipEnabled.Value : service.GZipEnabled); - AddETag(request); return request; } @@ -233,15 +232,25 @@ IDirectResponseSchema body = GetBody() as IDirectResponseSchema; if (body != null && !string.IsNullOrEmpty(body.ETag)) { + var etag = body.ETag; ETagAction action = ETagAction == ETagAction.Default ? GetDefaultETagAction(HttpMethod) : ETagAction; - switch (action) + try { - case ETagAction.IfMatch: - request.Headers.IfMatch.Add(new EntityTagHeaderValue(body.ETag)); - break; - case ETagAction.IfNoneMatch: - request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(body.ETag)); - break; + switch (action) + { + case ETagAction.IfMatch: + request.Headers.IfMatch.Add(new EntityTagHeaderValue(etag)); + break; + case ETagAction.IfNoneMatch: + request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(etag)); + break; + } + } + // When ETag is invalid we are going to create a request anyway. + // See https://code.google.com/p/google-api-dotnet-client/issues/detail?id=464 for more details. + catch (FormatException ex) + { + Logger.Error(ex, "Can't set {0}. Etag is: {1}.", action, etag); } } }