Recently I worked intensively with Azure Batch. During the work, there were couple of problems (as usual). One of them were too long task id or containing illegal characters in task id.
In the effect the
Microsoft.Azure.Batch.AddTaskCollectionTerminatedException was thrown. In the details of that exception I found the following message:
Error.Code=InvalidPropertyValue, Error.Message=The value provided for one of the properties in the request body is invalid.. The cause of that exception was as I said the length and non-allowed chars in task id:
Task ids can only contain any combination of alphanumeric characters along with dash (-) and underscore (_). The name must be from 1 through 64 characters long.
This had happened because the task id was dynamically created and consists Guid of the Batch Job and the name of the file. This dynamic creation of the kas id resulted in waaaay too long sting. The problem was also the characters. Only alphanumeric, underscore and hyphen chars are allowed. Any special characters, spaces, colons, etc. are not allowed.
Once you found the problem, the solution is trivially simple. Task id needs to have only allowed characters and be shortened to a maximum of 64 characters. For this purpose I made an extension method:
Probably you think why not use regex here? Well, the Regex was 3 times slower than the above solution made with LINQ. Why even bother about the time? Because I use this method inside Azure Function. In Functions you not only pay for the amount of the Function invocation number but for the function run time also.