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

Shantimohan Elchuri 176 Reputation points
2021-08-18T17:41:23.193+00:00

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:

System.TypeInitializationException
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  
            .Children  
            .Request()  
            .GetAsync();  
Xamarin
Xamarin
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
    2021-09-09T15:34:40.37+00:00

    @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">
    <IncludeAssets>none</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Buffers" Version="4.5.1">
    <IncludeAssets>none</IncludeAssets>
    </PackageReference>

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    2021-09-06T06:22:32.943+00:00

    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.