Microsoft Graph .NET SDK v4 now generally available with streamlined authentication and more
If you already work with Microsoft Graph, then you know how powerful it is to have a single REST API to access data across many Microsoft services. Microsoft Graph .NET SDK provides a fluent API and models that support retry handling, secure redirects, batching requests, large file management, and many more capabilities.
Today we’re announcing the general availability (GA) of Microsoft Graph .NET SDK version 4.0.
Along with all the features and improvements discussed in the v4 preview announcement, such as single authentication against Microsoft Graph and Azure Identity clients and easy access to response information through the GraphResponse object, this GA release also delivers the new capabilities described below.
Rich notifications that support encrypted content
The SDK now includes native support to decrypt resource data in rich notifications payloads.
When creating a subscription, Microsoft Graph .NET SDK v4 users can simply use the AddPublicEncryptionCertificate method to add a certificate. Once the subscription is created, use the AreTokensValid and DecryptAsunc functions, to respectively validate the tokens and decrypt the content in the notification payload.
Rich notifications provide encrypted changed data along with the change notifications, saving the subscriber from having to call back Microsoft Graph to fetch the data, thereby improving application performance. You can read more about this feature in the documentation.
Improved testability of GraphServiceClient
The IGraphServiceClient interface has been used by Microsoft Graph .NET SDK users to build application tests that depend on GraphServiceClient. Using this interface, however, causes code breaks whenever the Microsoft Graph metadata changes, making it less than ideal for mocking or inheriting.
To improve users’ experience, the interface has been removed in Microsoft Graph .NET SDK v4. Properties and methods of GraphServiceClient have been made virtual, allowing mocking frameworks to override them. Users do not have to create real objects to test the application.
ODataType is no longer specified by default
Since the release of Microsoft Graph .NET SDK v3, generated types have had the ODataType property set by default in the SDK. Even though this was not a problem at the time, Microsoft Graph has continued to grow and more APIs have been onboarded, the ODataType property has started to cause errors during its serialization to some of the APIs.
In v4, the ODataType property is only set in cases where type disambiguation is required, for example:
- When the type is derived from an abstract type.
- When one of its base types is referenced as the type for a property on another type, unless the base is an entity, e.g., OrganizerMeetingInfo has its base type MeetingInfo referenced as the type of a property on another type.
- When one of its base types is referenced as a type in an OData action of another type, unless the base type is entity, e.g., AppHostedMediaConfig has its base type MediaConfig referenced in an action.
Get started with Microsoft Graph .NET SDK v4
To get familiar with the Microsoft Graph SDKs, start with the documentation page.
The upgrade guide will guide you through the migration and provide examples for implementing the new features, helping you quickly take advantage of all the new capabilities.
Start saving time and removing complexity in your code today. Whether you prefer a barebone client or a fluent API, you can choose between the Microsoft Graph .NET SDK Core or the Microsoft Graph .NET SDK Client, whichever best suits your needs.
Sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 developer subscription, and start building .NET Core apps with Microsoft Graph.
We’d like to thank all the members of the community who have helped us make this release better by reporting issues in GitHub!
Here are some of the feedback we would like to highlight: Andreas Jakof, Sudheer Achary, Nate Latchaw, schmid37, Danial Mazahreh, pbaumhart, Dean Kinane, Cory Grimster, and Michael Hawker.
Keep them coming!
Try out the new version today!
Try out this new version and let us know what you think on GitHub! Ask questions at Microsoft Q&A.