chargebee-dotnet icon indicating copy to clipboard operation
chargebee-dotnet copied to clipboard

It's impossible to add `.Header()` to certain types of requests

Open nfidirko opened this issue 1 year ago • 0 comments

Description

For certain types of requests (e.g. deleting a payment source), when you're trying to add a header via .Header() an exception is thrown.

Affected versions

  • 3.8.0
  • 3.9.0

(Haven't tests earlier version)

Code to reproduce the error

var request = ChargeBee.Models.PaymentSource.Delete("test");
request.Header("test", "test");

Exception

Unhandled exception. System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at ChargeBee.Api.EntityRequest`1.Header(String headerName, String headerValue)
   at Program.<Main>$(String[] args) in ......

Notes

It looks like this error occurs in all requests that have type EntityRequest<Type>. The error is thrown here: (T) Convert.ChangeType((object) this, typeof (T));. It also means that for such requests it's not possible to set idempotency key or add a parameter to such request.

nfidirko avatar Sep 21 '23 09:09 nfidirko