0

I recently started deploying my fully functional Twitter bot (which is supposed to post a new short story every day or so) to my Twitter profile. It is being invoked through a CRON job on Azure, and is hosted in an MVC 4 project.

However, when I try to run it in Azure (and remember, it works fine locally), I get the following error:

[NetworkInformationException (0x5): Access is denied]
   System.Net.NetworkInformation.SystemIPGlobalProperties.GetFixedInfo() +9059627
   System.Net.NetworkInformation.SystemIPGlobalProperties.get_FixedInfo() +172
   System.Net.NetworkInformation.SystemIPGlobalProperties.get_DomainName() +269
   System.Net.CookieContainer..ctor() +121
   Hammock.Web.WebQuery.AppendCookies(HttpWebRequest request) +242
   Hammock.Web.WebQuery.SetRequestMeta(HttpWebRequest request) +147
   Hammock.Web.WebQuery.HandleRequestMeta(WebRequest request) +146
   Hammock.Web.WebQuery.BuildPostOrPutFormWebRequest(PostOrPut method, String url, Byte[]& content) +680
   Hammock.Web.WebQuery.BuildPostOrPutWebRequest(PostOrPut method, String url, Byte[]& content) +168
   Hammock.Web.WebQuery.ExecutePostOrPut(PostOrPut method, String url, WebException& exception) +181
   Hammock.Web.WebQuery.Request(String url, WebException& exception) +252
   Hammock.Authentication.OAuth.OAuthWebQuery.Request(String url, WebException& exception) +157
   Hammock.RestClient.RequestImpl(RestRequest request) +943
   Hammock.RestClient.Request(RestRequest request) +74
   TweetSharp.TwitterService.WithHammockImpl(RestRequest request) +83
   TweetSharp.TwitterService.WithHammock(WebMethod method, String path) +120
   TweetSharp.TwitterService.SendTweet(SendTweetOptions options) +782

I assume it's because it uses a port that Azure doesn't support or something similar. Or is it? I have no clue where to begin troubleshooting this, and there has been no help to find on the web when I searched for it.

Here's my code. As you can see, the access tokens and secrets are hard-coded in, and they are (like I said) working locally:

var service = new TwitterService("qwdwqdqwd", "qwdwqdqwdqwd");
service.AuthenticateWith("qwdqwdqwdqwd", "qwdqwdqwdwqd");

var status = "Collaborative short story of the day: Blah";
var response = service.SendTweet(new SendTweetOptions() {Status = status}); //crash!

What is the issue?

Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187

2 Answers2

1

Do you run your project in Azure Web Site or Azure Cloud Service?

Given the StackTrace, and digging a bit around it appears that SystemIPGlobalProperties uses some unsafe methods. Using unsafe methods requires full trust:

Caution Code written using an unsafe context cannot be verified to be safe, so it will be executed only when the code is fully trusted. In other words, unsafe code cannot be executed in an untrusted environment

Also a low level access to system components might require Elevation of privileges. Windows Azure Web Sites does not support Full Trust, so you can't run this code in Azure Web Sites.

If you run Cloud Service, make sure that your code runs in Full Trust. If this does help, then run your code with elevated privileges. (runtime element in your csdef file)


astaykov
  • 30,768
  • 3
  • 70
  • 86
  • It is indeed an Azure website. So there's no hope for me then unless I make a service for it? – Mathias Lykkegaard Lorenzen Jun 05 '13 at 11:38
  • Give a try with a Cloud Service - if it works there, I'm afraid that either Hammock shall change how they execute web requests, or you have to go for a Cloud Service where you have more control on the environment. – astaykov Jun 05 '13 at 11:44
0

The problem fixed itself. I let the site run for a few weeks, and all of a sudden, I noticed tweets coming from the account. The CRON job had been running every day, and had a lot of error 500 messages, but then all of a sudden (without touching the code), it worked.

Must have been some under-the-hood changes the Azure team made.

Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187