janssenr / SendCloudApi.Net

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

Models.DocumentTypeExtensions.ToDocumentType() generates error #15

Closed mpiesens closed 2 years ago

mpiesens commented 2 years ago

Hi,

I found an error in the ToDocumentType() function in the Model.Documentype.cs class. It gives us a "ToEnumValue(): Invalid description for enum DeliveryOption" error.

On line 39 it says: var type = typeof(DeliveryOption); I think DeliveryOption should be DocumentType

janssenr commented 2 years ago

Should be fixed now.

mpiesens commented 2 years ago

Unforunately I am still getting the error. I updated the nuget package to version 2.0.14.0 Is this the latest version, including the fix?

janssenr commented 2 years ago

2.0.14 should be the latest version. Do you have a replication procedure for me? Then I can test the code myself.

mpiesens commented 2 years ago

I am trying to create a Parcel, containing 2 ParcelItems, with a shipping adres in London(GB). While sending from de Netherlands(NL), this should create a Customs Declaration Form. This gives an error on SendCloudApi.Net.SendCloudApi.Parcels.Create(parcel) I can view the parcel in Sendcloud, including the Customs Declaration Form, so creation itself seems to work.

When I create a Parcel for shipping inside the EU, so no Customs Declaration Form is created, it al works fine and I am able to print the label.

janssenr commented 2 years ago

Can you sent me a code example which results in the Error?

mpiesens commented 2 years ago

private async void createParcel() { var sendCloudClient = new SendCloudApi.Net.SendCloudApi(apiKey, apiSecret);

var parcel = new CreateParcel
{
    Name = "Mano Test",
    Address = "Downingstreet",
    HouseNumber = "10",
    City = "London",
    PostalCode = "SW1A 2AA",
    Country = "GB",
    RequestLabel = true,
    ApplyShippingRules = true,
    ShippingMethod = (int)enumShipMethod.DeutschePost,
    OrderNumber = "12345",
    AddressDivided = new AddressDivided()
    {
        Street = "Downingstreet",
        HouseNumber = "10"
    },
    Telephone = "",
    Email = "",
    CountryState = "",
    CustomsInvoiceNr = "12345",
    CustomsShipmentType = CustomsShipmentType.CommercialGoods,
    Weight = 0.470
};

parcel.ParcelItems = new ParcelItem[]{
    new ParcelItem()
    {
        Description = "T-shirt - Arnhem Rolls",
        Quantity = 1,
        Weight = 0.235,
        Value = 39.95,
        HarmonizedSystemCode = "61091000",
        OriginCountry = "NL",
        StockKeepingUnit = "0264.M.T.009B.O.XL",
        ProductId = "PROD-B23CQ6"
    },
    new ParcelItem()
    {
        Description = "T-shirt - The Sky Is The Limit",
        Quantity = 1,
        Weight = 0.235,
        Value = 39.95,
        HarmonizedSystemCode = "61091000",
        OriginCountry = "NL",
        StockKeepingUnit = "0327.M.T.029.O.XXXL",
        ProductId = "PROD-C2PK2C"
    }
};

try
{ 
    var response = await sendCloudClient.Parcels.Create(parcel);
}
catch (SendCloudApi.Net.Exceptions.SendCloudException e)
{
    throw new Exception(e.Message);
}

}

janssenr commented 2 years ago

I think it was related to a typo fix which I fixed today. A typo in commercial-invoice (different dash). Can you update to NuGet package 2.0.16 and check if your issue is solved?

mpiesens commented 2 years ago

Unfortunately I am still getting the same error! Maybe the stacktrace can be of help?

at SendCloudApi.Net.Models.DocumentTypeExtensions.ToDocumentType(String enumerationDescription) at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader) at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream) at SendCloudApi.Net.Helpers.JsonHelper.DeserializeAsDictionary[T](String json, String dateTimeFormat) at SendCloudApi.Net.SendCloudApi.d30`1.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SendCloudApi.Net.SendCloudApi.d251.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SendCloudApi.Net.Resources.SendCloudApiAbstractResource.<Create>d__141.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SendCloudApi.Net.Resources.SendCloudApiParcelsResource.d__2.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at OKI_SCAN.Form1.d__25.MoveNext() in E:\Projecten\VisualStudio\Okimono\OkiOrders\OkiOrders\Form1.cs:line 333

janssenr commented 2 years ago

There was also a typo in cn23-default (different dash). Can you please try version 2.0.17?

mpiesens commented 2 years ago

Yes, that was it! It is working fine now! Thank you very much!