CreateTicket crashes if TicketAttachment.Data is not an empty string

Infos:

  • Used Zammad version: Zammad.Client 1.2.33 C# (.NET client from docs.zammad.org)
  • Used Zammad installation type: NuGet under VisualStudio 2022 Version 17.4.4
  • Operating system: Windows 10 pro
  • Browser + version: not used

Expected behavior:

  • create a ticket with attachment and send as email

Actual behavior:

  • crashes if TicketAttachment.Data is not an empty string

Steps to reproduce the behavior:

  • create a ticket and an article with an attached csv file
  • call ticketClient.CreateTicketAsync(ticket,article) with them

Code

var now = DateTime.Now;
var csvText = "a";

var ticketArticle = new TicketArticle()
{
    TicketId = 123,
    To = "example@email.com",
    CC = "",
    Subject = "not closed tickets | " + now,
    Body = "See attachments",
    ContentType = "text/plain",
    Type = "email",
    Internal = true,
    Sender = "Agent",
    Attachments = new List<TicketAttachment>()
    {
        new TicketAttachment()
        {
            Filename = "not closed tickets | " + now + ".csv",
            Data = csvText,
            MimeType = "text/plain"
        }
    }
};

var ticket = new Ticket()
{
    Title = "not closed tickets | " + now,
    GroupId = 1,
    CustomerId = 1,
    OwnerId = 1,
};

var r = ticketClient.CreateTicketAsync(ticket, ticketArticle).Result;

with csvText == “” it works all fine, the ticket is created and the email delivered
with csvText == “a” it throws an exception on the last line (var r = ticketClient.CreateTicketAsync(ticket, ticketArticle).Result;), the exception is as follows:

System.AggregateException
HResult=0x80131500
Message = One or more errors occurred. (Unprocessable Entity)
Source= System.Private.CoreLib
Stacktrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task1.get_Result()
at Zammad_News.Program.Main() in C:\Users\username\source\repos\Zammad News\Program.cs: Row111

I tested it multiple times, in random order, different characters, strings of different length.
It works if csvText is empty, it doesn’t if it isn’t.

I figured out the solution:

Data = Convert.ToBase64String(Encoding.UTF8.GetBytes("a"))

instead of

Data = "a"

this way it works

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.