Outlook/Office iCal feed 400 bad request error with C# WebClient

By Robert Ellison. Updated on Tuesday, June 21, 2022.

400

Just in case it helps someone else I was able to fetch an Outlook iCal feed using C#'s WebClient for years until it stopped working in June, 2022 with a 400 / bad request error. I was downloading a set of calendars and the fix was just to use a new WebClient for each calendar so it must be some kind of state thing in WebClient.

To regain around 1% of sanity I have a task that pulls the various calendars that life throws at me and combines them into a single, de-duplicated calendar. The Google Calendar on my phone is gorgeous as a result. My primary calendarĀ is orange and then all of the miscellanea are teal and unique. It would be great if Google Calendar could do this without help, but it was worth the effort not to have some random soccer match repeated five times in different colors.

Last week one calendar, an Outlook feed, started failing with 400 bad request.

Naturally I assumed that the server had started to suddenly care about some header or other and I started playing around with setting User-Agent and various Accept headers without any luck. To make debugging slightly easier I moved the Outlook calendar out of a loop (where I was iterating through a list of iCal feeds that I need to be aware of) and then it magically started working. The magic in this case must be a fresh WebClient and so the fix was to use a new WebClient for each calendar instead of reusing a single instance. It looks like WebClient is deprecated in .NET 6 and one is supposed to start using HttpClient instead so that's probably another fix but not one I'm going to wrestle with today.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Outlook/Office iCal feed 400 bad request error with C# WebClient #code #c# #outlook How to fix a 400 / bad request error with the C# WebClient when downloading an Office iCal feed. )

Comments

Jukka P.

We had the same problem and your advice helped. Huge Thanks!!

Add Comment

All comments are moderated. Your email address is used to display a Gravatar and optionally for notification of new comments and to sign up for the newsletter.