1

I am using Twilio Conversation and generating JWT for token.

When calling new Twilio.Jwt.AccessToken(/*parameters*/).ToJwt() method, it causes

'token.ToJwt()' threw an exception of type 'System.ArgumentException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147024809
    HelpLink: null
    InnerException: null
    Message: "An item with the same key has already been added. Key: cty"
    ParamName: null
    Source: "System.Private.CoreLib"
    StackTrace: "   at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)\r\n   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\r\n   at Twilio.Jwt.BaseJwt.ToJwt()"
    TargetSite: {Void ThrowAddingDuplicateWithKeyArgumentException[T](T)}

Why this causes?

Takeo Nishioka
  • 369
  • 2
  • 11

1 Answers1

1

Keep Microsoft.Graph version is same or below 4.30.0. My case was that It stopped throwing the exception after that.

This error happens once you install Microsoft.Graph with version above 4.31.0. Apparently either Microsoft.Graph or Twilio nuget packages need to be fixed.

Takeo Nishioka
  • 369
  • 2
  • 11
  • In my case I also had to update the [System.IdentityModel.Tokens.Jwt](https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/) NuGet package – George Dec 20 '22 at 23:39