EienYuki / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

ContactsRequest.Insert() fails with System.Net.ProtocolViolationException #692

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I followed this documentation on the contacts api 
https://developers.google.com/google-apps/contacts/v3/#creating_contacts for 
creating a new contact.

Create a new Contact and populate with data like phone, email etc.

    var newEntry = new Contact();

Construct a new uri and issue an Insert on a standard contacts request.

    var feedUri = new Uri("https://www.google.com/m8/feeds/contacts/default/full");
    myContactsRequest.Insert(feedUri,newEntry);

Sometimes(with no changes in my code) I get this exception:

System.Net.ProtocolViolationException : When performing a write operation with 
AllowWriteStreamBuffering set to false, you must either set ContentLength to a 
non-negative number or set SendChunked to true.
   at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
   at System.Net.HttpWebRequest.GetResponse()
   at Google.GData.Client.GDataRequest.Execute()
   at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
   at Google.GData.Client.GOAuth2Request.Execute()
   at Google.GData.Client.Service.EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data)
   at Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData data)
   at Google.GData.Client.Service.Insert(Uri feedUri, TEntry entry)
   at Google.GData.Client.FeedRequest`1.Insert(Uri address, Y entry)
   at covve.Providers.Tests.GmailApiLearningTests.GoogleApiCallAddContact() in GmailApiLearningTests.cs: line 124

And sometimes my code works just fine. It appears as if some non deterministic 
variable is affecting the result and the stack trace seems to be out of my 
code's scope. Note that my OAuth2properties and settings are working fine on 
myContactsRequest.GetContacts(), so I suppose it's not an authorization/token 
issue. Also, using the alternative syntax of insert:

myContactsRequest.Insert(Feed<Contact> feed, Contact)

has always worked as expected, despite the fact that both methods of insert are 
alternatives for the same functionality.

Additional info:

Google.GData.Client version: 2.2.0.0
.NET framework 4.5 (vs 2013, version 4.5.51.641)

Original issue reported on code.google.com by kaiseros...@gmail.com on 19 May 2014 at 2:54