twilio-csharp
twilio-csharp copied to clipboard
Invalid URI exception thrown when updating a workflow
Issue Summary
When updating or saving a workflow with a configuration that exceeds 65519 characters an exception is thrown. "Invalid URI: The Uri string is too long". Attached example workflow. Twilio's documentation says the maximum workflow size is 1MB, this request is within the size limit.
Steps to Reproduce
- Create a new workflow
- Copy the workflow json from Twilio into a new file named "exampleWorkflow.txt"
- Place the file in a C# project and configure the file properties "Copy to Output Directory" to "Copy always"
- Edit the text file to exceed 65519 in character length with any valid workflow configuration
- Replace the "workspaceSid" and "workflowSid" in the below code snippet
- Run the code snippet
Code Snippet
var workspaceSid = "?";
var workflowSid = "?";
var workflowConfiguration = File.ReadAllText("exampleWorkflow.txt"); // see attached
var workflowOptions = new UpdateWorkflowOptions(workspaceSid, workflowSid)
{
Configuration = workflowConfiguration,
FriendlyName = "Debug Workflow Size"
};
var updatedWorkflow = await WorkflowResource.UpdateAsync(workflowOptions);
Exception/Log
"Invalid URI: The Uri string is too long" at System.UriHelper.EscapeString(String input, Int32 start, Int32 end, Char[] dest, Int32& destPos, Boolean isUriString, Char force1, Char force2, Char rsvd)
at System.Uri.EscapeDataString(String stringToEscape)
at System.Net.Http.FormUrlEncodedContent.Encode(String data)
at System.Net.Http.FormUrlEncodedContent.GetContentByteArray(IEnumerable`1 nameValueCollection)
at System.Net.Http.FormUrlEncodedContent..ctor(IEnumerable`1 nameValueCollection)
at Twilio.Http.SystemNetHttpClient.MakeRequestAsync(Request request)
at Twilio.Clients.TwilioRestClient.RequestAsync(Request request)
Technical details:
- twilio-csharp version:
- csharp version:
This issue has been added to our internal backlog to be prioritized (ref DI-2231).
After a deep analysis, we have determined the issue lies out of our domain and therefore will not be making any changes to twilio-csharp.
Reasoning
We were able to recreate the error on .NET framework version 4.8, but were unable to recreate it in .NET Core version 6. We looked deeper into how our code utilizes .NET framework to see if we could resolve the issue on our side, but the twilio-csharp code is (almost) identical to how it is generated for .NET core. Because of this, we diagnosed it as an issue exclusive to .NET framework.
Tracing the issue shows that the root cause of the issue lies in the .NET framework API and not the helper library. We recommend looking into upgrading your runtime .NET version, if possible.
This issue has been previously raised by the community and it seems that the fix is only in .net core.
Leaving the issue open for now, so please let me know if you have any concerns.