disasterkid
disasterkid

Reputation: 7278

Google Analytics GetRequest Error: System.Net version 2.0.5.0 Needed to see HttpStatusCode

I'm using Google Analytics Core Reporting API. I can successfully run my request with a code like this.

DataResource.GaResource.GetRequest requestData = googleAnalyticsService.Data.Ga.Get(profiles, startDateStr, endDateStr, metrics);
requestData.Dimensions = dimensions;
requestData.MaxResults = Globals.MAX_RESULTS;

responseData = requestData.Execute();

So in my responseData object I have all the data that I need. But I also need to know when I have an error in my request. So I need to catch a GoogleApiException that has an HttpStatusCode property. This Http status code will let me know if I have reached my quota of requests per day so I can continue receiving information 24 hours after that. But when I catch an exception like this:

catch (GoogleApiException gapiex)
{
   logger.WriteToLog("GETPROFILEDATA", "Google API exception: " + gapiex.HttpStatusCode);
   break;
}

I get an error that says:

The type 'System.Net.HttpStatusCode' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

And I cannot seem to find the library neither via NuGet nor elsewhere. Is there another way of getting the status code or does anyone have the library somewhere?

Upvotes: 0

Views: 579

Answers (1)

peleyal
peleyal

Reputation: 3512

Make sure your .NET framework is patched. Microsoft released patches to .NET to allow Portable Class Libraries to properly find the appropriate runtime. KB2468871 patch is available at http://www.microsoft.com/en-us/download/details.aspx?id=3556.

If you are seeing the above exception (or something like it), it means you're missing the latest .NET framework patches.

Upvotes: 1

Related Questions