#StackBounty: #c# #asp.net #iis #asp.net-core Splitting a string throws InvalidOperationException when hosting on IIS

Bounty: 50

I wrote the following code:

private string makeMailContents(Klant klant, Mail mail)
    var builder = new BodyBuilder();
    var path = Path.Combine("wwwroot/trackers/track_open.png");
    var img = builder.LinkedResources.Add(path);
    byte[] data = Convert.FromBase64String(mail.Content);
    string decoded = Encoding.UTF8.GetString(data);
    string code;
    string final = "";
    Regex regReplace = new Regex(@"[([^]]*)]");

    img.ContentId = MimeUtils.GenerateMessageId();

    var splitContent = decoded.Split(' ');

    foreach(string word in splitContent) { // something }

Whenever I run this code on my local machine and my test server it executes the code like it should without any exceptions.

But whenever I host this on my current live server it throws the following exception:

InvalidOperationException: Sequence contains no elements

And this exceptions keeps pointing towards the splitContent and it tells me that it doesn’t contain elements. And yes, the mail.Content is filled with a valid base64 string, I checked both with fiddler and postman.

Does anyone have the slightest clue of what’s going on here? I’m also not sure if it’s the IIS settings or somehow my code. I normally have a colleague who manages the IIS but he is on vacation right now. Can someone help me out with this?

This is the data the mail receives when called:

    "Onderwerp":"Dit is een test campagne",
    "verzenddat":"8/17/18, 3:55 PM"

Whenever I run this code in my values controller to test the decoded.split(' ') it actually works. When I return the decoded.split(' ') I actually get an array of strings.

So now I know that the problem only occurs within the method, which is located in a Sender class and being called in the MailerController, and it also only occurs in the current server.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.