janssenr / SendCloudApi.Net

A C#/.net wrapper for the SendCloud API
MIT License
6 stars 5 forks source link

Exception with Verbose mode #25

Closed NathanLD closed 1 year ago

NathanLD commented 1 year ago

Hi,

I seem to have a problem when I activate the verbose mode.

Without verbose mode, this code works :

var client = new SendCloudApi.Net.V2.SendCloudApi("xxx", "yyy");

var putParcel = new CreateParcel
{
    Id = 12345,
    Name = "NAME"
};
await client.Parcels.Update(putParcel);

But with verbose mode : var client = new SendCloudApi.Net.V2.SendCloudApi("xxx", "yyy", verbose: true); The same code throws a NullReferenceException : System.NullReferenceException: 'Object reference not set to an instance of an object.'

After investigation, it seems that the error is in SendCloudApiBase.cs:L114, where parameters is null : parameters.Add("errors", "verbose-carrier");

The reason is that the Update<T> method pass null instead of a Dictionary :

internal async Task<ApiResponse<T>> Update<T>(string url, string authorization, string data, string returnObject, string dateTimeFormat, bool verbose)
{
    return await SendRequest<T>(url, authorization, "PUT", null, data, returnObject, dateTimeFormat, verbose);
}

I see that only the Get<T> method pass a Dictionary, but the other methods pass null.

Did i miss something, or is there really an issue there ?

janssenr commented 1 year ago

I fixed the issue. if (parameters == null) parameters = new Dictionary<string, string>();