OneDrive Graph Client throwing System.TypeInitializationException in Xamarin.iOS project only

Shantimohan Elchuri 176 Reputation points

This was working till few days back. It appears one of the recent updates to Xamain.iOS has broken it.

I have implemented OneDrive client in my project as per Build Xamarin apps with Microsoft Graph.

This is a Xamarin Forms project. Installed Microsoft.Graph only in the common project and installed Microsoft.Identity.Client in all projects.

After successful login into OneDrive Service, it is throwing the following exception:

Message=The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.

It is failing executing the following code:

        IDriveItemChildrenCollectionPage files = null;  
        files = await OdGraphClient.Me.Drive.Root  
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,821 questions
{count} votes

Accepted answer
  1. Shantimohan Elchuri 176 Reputation points

    @Deva-MSFT The actual resolution was found in the accepted answer of jsonserializer-throws-exception-in-xamarinios.html

    Added the following lines to iOS project file in the ItemGroup containing Package References:

    <PackageReference Include="System.Memory" Version="4.5.4">
    <PackageReference Include="System.Buffers" Version="4.5.1">

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee

    I would suggest you to get the latest pull and see if you can repro the issue. If yes, then report the issue at the project issues list.