twilio-csharp icon indicating copy to clipboard operation
twilio-csharp copied to clipboard

Invalid URI exception thrown when updating a workflow

Open egokick opened this issue 1 year ago • 2 comments

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

  1. Create a new workflow
  2. Copy the workflow json from Twilio into a new file named "exampleWorkflow.txt"
  3. Place the file in a C# project and configure the file properties "Copy to Output Directory" to "Copy always"
  4. Edit the text file to exceed 65519 in character length with any valid workflow configuration
  5. Replace the "workspaceSid" and "workflowSid" in the below code snippet
  6. 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)

exampleWorkflow.txt

Technical details:

  • twilio-csharp version:
  • csharp version:

egokick avatar Jul 12 '22 20:07 egokick

This issue has been added to our internal backlog to be prioritized (ref DI-2231).

childish-sambino avatar Jul 18 '22 14:07 childish-sambino

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.

mattcole19 avatar Aug 30 '22 21:08 mattcole19