I’m walking through a console app tutorial from Microsoft to deal with outlook mail here
I did everything as is, but when I try to test it I get this exception when the GET request is sent.
Content type text/html does not have a factory registered to be parsed.
The code:
public static Task<MessageCollectionResponse?> GetInboxAsync()
{
// Ensure client isn't null
_ = _userClient ??
throw new System.NullReferenceException("Graph has not been initialized for user auth");
return _userClient.Me
// Only messages from Inbox folder
.MailFolders["Inbox"]
.Messages
.GetAsync((config) =>
{
//The next two lines were added by me to try to fix the problem
config.Headers.Clear();
config.Headers.Add("Accept", "application/json");
// Only request specific properties
config.QueryParameters.Select = new[] { "from", "isRead", "receivedDateTime", "subject" };
// Get at most 25 results
config.QueryParameters.Top = 25;
// Sort by received time, newest first
config.QueryParameters.Orderby = new[] { "receivedDateTime DESC" };
});
}
2
Answers
I followed same link and registered one Azure AD application with Supported account type as below and enabled public client flows:
I have one tenant named DemoAAD having
Azure AD Free
license like below:In my case, I got same error when I ran same code by signing in with user from above tenant:
Response:
I have another tenant with
Azure AD Premium P2
license like below:In above tenant, I assigned an active Office 365 license to one user account:
When I ran same code, I picked user account having active Office 365 license from
Azure AD Premium P2
licensed tenant to login where I got consent prompt like this:After accepting the consent, I entered
2
and got list of inbox messages successfully in console output like below:Response:
Reference:
c# – Using Azure MS Graph API Service Account – Stack Overflow by Rukmini
this error
Content type text/html does not have a factory registered to be parsed
means you got an html content as the response which always indicating the request got error.My suggestion to narrow down the issue is: