A Quick Note About DynamicValue Objects in Workflows

I'm still, for some reason, flummoxed by how to effectively debug a DynamicValue object. In SharePoint 2013, it's no longer possible to write server-side code directly in a workflow class (as we all know by now). These days, you'll have to call one of the SharePoint CSOM REST services or something like that using the HttpSend workflow activity to perform many of the operations that you used to do in a code activity in SharePoint 2007 or 2010. There are plenty of tutorials available to teach you how to set up parameters, but it frequently doesn't go that easy. So what do you do when things just aren't working?

Well, I know what you can't do, because it will cause the workflow to suspend and terminate.

What you don't do, is call DynamicValue.ToString() in a WriteToHistory activity. I desperately wanted to see what the JSON return value looked like in the workflow, or even the response headers, and I really hoped that it would deliver something to my history log that I could work with. But no, the workflow died, went to a suspended state, and eventually dropped this under the "information" icon on the workflow status page:

RequestorId: dcfe3e96-d4ab-be6a-0000-000000000000. 
Details: RequestorId: dcfe3e96-d4ab-be6a-0000-000000000000. 
Details: An unhandled exception occurred during the execution of the workflow instance. 
Exception details: System.ApplicationException: HTTP 500
{
    "Transfer-Encoding": ["chunked"],
    "X-SharePointHealthScore": ["0"],
    "SPClientServiceRequestDuration": ["20"],
    "SPRequestGuid": ["dcfe3e96-d4ab-be6a-8784-0176cb71f2cd"],
    "request-id": ["dcfe3e96-d4ab-be6a-8784-0176cb71f2cd"],
    "X-FRAME-OPTIONS": ["SAMEORIGIN"],
    "MicrosoftSharePointTeamServices": ["15.0.0.4420"],
    "X-Content-Type-Options": ["nosniff"],
    "X-MS-InvokeApp": ["1; RequireReadOnly"],
    "Cache-Control": ["max-age=0, private"],
    "Date": ["Sat, 20 Dec 2014 12:46:02 GMT"],
    "Server": ["Microsoft-IIS\/8.0"],
    "X-AspNet-Version": ["4.0.30319"],
    "X-Powered-By": ["ASP.NET"]
}
at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) 
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) 

Which isn't the most helpful information. Doesn't tell you which activity, what the actual error is, anything helpful. Anyway, you'll probably see an error like this from time to time, and your error cause might not be the same as mine, but if you're messing with REST service calls and you want to see the results, go fire up Fiddler and find the request to look at the response. Don't try to call ToString() on the DynamicValue that comes back.