Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

DelegateAuthenticationProvider no longer exists in the Microsoft Graph .NET SDK

ErrorThe type or namespace name 'DelegateAuthenticationProvider' could not be found

Short answer

Microsoft Graph .NET SDK v5 removed DelegateAuthenticationProvider. Pass an Azure.Identity TokenCredential to the GraphServiceClient constructor instead. If you already hold an access token or need a custom flow, implement the Kiota IAccessTokenProvider interface and wrap it in a BaseBearerTokenAuthenticationProvider.

  • Applies to Microsoft.Graph 5.x, Azure.Identity, .NET 8 and 9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which Microsoft.Graph version the project resolves. Version 5 or later is the one without the class.

    dotnet list package | grep -i microsoft.graph
  2. 2Match what you see, then jump to its fix

    1. 1The compiler error appears right after a Microsoft.Graph package upgradeThe project moved to v5, which authenticates with Azure.Identity credentialsFix
    2. 2Old code returned a token string inside the delegateYou already have an access token, or your sign-in flow is customFix
    3. 3Requests reach Graph but arrive with no Authorization headerYou pass your own HttpClient, and it carries no authenticationFix

What does the error look like?

  • The type or namespace name 'DelegateAuthenticationProvider' could not be found

Cause 1 of 3

The project moved to v5, which authenticates with Azure.Identity credentials

1Check

The v5 upgrade guide says the GraphServiceClient constructor accepts a TokenCredential from Azure.Identity, in place of DelegateAuthenticationProvider.

dotnet list package | grep -i -E "microsoft.graph|azure.identity"

2Fix

Add Azure.Identity, create the credential that matches your app type, and pass it with the scopes. A daemon app uses a client secret credential and the .default scope.

dotnet add package Azure.Identity

// C#
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(credential, new[] { "https://graph.microsoft.com/.default" });

3Verify

Build the project and call one simple endpoint.

dotnet build
// C#
var me = await graphClient.Users.GetAsync();

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

You already have an access token, or your sign-in flow is custom

1Check

The v5 guide says custom flows are done by implementing the Kiota IAccessTokenProvider interface, which returns a token for a given URI.

grep -rn "DelegateAuthenticationProvider" --include=*.cs .

2Fix

Write a small IAccessTokenProvider that returns your token, wrap it in BaseBearerTokenAuthenticationProvider and hand that to GraphServiceClient.

// C#
var authProvider = new BaseBearerTokenAuthenticationProvider(new TokenProvider());
var graphClient = new GraphServiceClient(authProvider);

3Verify

The first call returns data instead of a 401.

// C#
var me = await graphClient.Me.GetAsync();

Confirmed by github.com

Did this fix it?

Cause 3 of 3

You pass your own HttpClient, and it carries no authentication

1Check

The guide states that authentication is no longer handled in the HttpClient middleware pipeline, so a custom HttpClient must already handle it.

grep -rn "new GraphServiceClient(" --include=*.cs .

2Fix

Give the client an authentication provider as the second constructor argument along with the HttpClient.

// C#
var graphClient = new GraphServiceClient(httpClient, authenticationProvider);

3Verify

Requests now carry a bearer token and Graph returns data.

// C#
var me = await graphClient.Me.GetAsync();

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Read the upgrade guide before raising a major version of the Graph SDK.
  • Keep client secrets in a secret store, not in the source.
  • Use the credential type that matches the app: client credentials for daemons, authorization code or on-behalf-of for user flows.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Security

A valid JWT fails to decode because its segments are base64url, not base64

Convert.FromBase64String throws FormatException on a JWT segment

A JWT is three base64url segments joined by dots, and a standard base64 decoder refuses all three differences: base64url uses - and _ instead of + and /, leaves off the = padding, and the dots are not part of any base64 alphabet.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.