NullReferenceException with request.ServicePoint.Expect100Continue = false;


As soon as I try to run the following code on either a Windows Mobile emulated or physical device ...
        Twitter twitter = new Twitter("ACCOUNTNAME", "PASSWORD");
        twitter.SetStatus("Test post!");
... I get a null reference exception here ...
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
        if (authenticate)
            request.Credentials = new NetworkCredential(username, password);
        request.UserAgent = twitterClientNameAndVersion;
        request.ReadWriteTimeout = c_DefaultTimeout;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ServicePoint.Expect100Continue = false;  // HERE is where the exception occurs!
ServicePoint is null.
However, if I run this in a regular WinForm or consule application, it works fine.
I'm pretty much using your framework with little to know changes. What's the issue?
Thanks, Wade
Closed Aug 18, 2009 at 8:43 AM by pschid2s
Property-value ServicePoint unavailable in CF environment, Bugfix commited.


pschid2s wrote Aug 18, 2009 at 8:42 AM

Hi Wade,

thanks for your hint. The problem was that the property ServicePoint is not set in mobile enivronments inevitably. A simple change of code to

if (request.ServicePoint != null)
 request.ServicePoint.Expect100Continue = false;

solves the problem. I changed the code within the repository and will create a new release soon with these changes included.

Thanks again and best regards

wrote Aug 18, 2009 at 8:43 AM

wwegner wrote Aug 18, 2009 at 12:18 PM

I'm pretty sure I tried this, and it didn't resolve the issue because Twitter will send a 417 - or whatever the error is - because they require you to set Expect100Continue to be false. So, while it doesn't throw an exception, you still can't actually post a tweet. Right?

beltragx wrote Aug 24, 2009 at 5:47 PM

I pulled down the latest source and am running into the same issue as the original poster. I verified the code was modified to match what you've posted here and I'm still getting the 417 error

wiedsche wrote Oct 2, 2009 at 9:10 AM

The NullReferenceException doesn't occour any longer with this fix - but using this lib to tweet doesn't work, too. Twitter sends 417 error, it expects Expect100Continue to be false. This is controversy. on one hand compact framework doesn't support the property-value ServicePoint, which is required to set Expect100Continue - on the other hand twitter requires this.
how can this be solved? is there a workaround for comapct framework to set Expect100Continue to false?

amitchintawar wrote Nov 26, 2009 at 10:43 AM

The issue can be solved by using HTTP 1.0 protocol instead of HTTP 1.1. Also you have to set the "AllowWriteStreamBuffering" to true as server gives exception.

wrote Feb 14, 2013 at 12:10 AM

wrote May 16, 2013 at 7:10 AM