Reputation: 3633
I have a C# plugin in Dynamics 2016 on-premise that uses a library to make calls to other systems. Part of that library is a call to dynamics using the Web API. The Plugin is taking action as I can see the changes in dynamics, however I am expecting it to take a different action than it is taking. When I try to debug the plugin using the Plugin Registration tool, I am running into some issues. When I profile the plugin using the Exception method, I get an exception file that I am able to debug through to a point. When I get to the below code, the Plugin Registration Tool crashes without an error message. When I debug using the Persist to Entity Method, my plugin appears to succeed, but no Profiles are logged in the Plugin Registration Tool. My plugin is fired from an action which is triggered from a workflow that is attached to the completion of a Business Process Flow (this is based on this article). My initial question is here which led to this question. Any thoughts on getting the debugger to work with my code?
HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential("admin", "password", "DOMAIN") });
client.BaseAddress = new Uri(Helpers.GetSystemUrl(COHEN.APIConnector.Application.Dynamics));
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
HttpResponseMessage responseMessage;
string url = "ccseq_clients";
responseMessage = client.GetAsync(url).Result;
Upvotes: 2
Views: 3713
Reputation: 22836
I remember this issue, when I was debugging SharePoint online REST API calls it will always crash. Then I added tracing service & logged checkpoints to verify the code execution path. Instead of debugging, I will download the Profiler trace log & replay in PRT to see success or failure branch.
When you configure plugin tracing to log All under system settings, it’s Dev mode & will be super helpful.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
tracingService.Trace("Attempting to obtain Phone value...");
phone = account["telephone1"].ToString();
}
catch(Exception error)
{
tracingService.Trace("Failed to obtain Phone field. Error Details: " + error.ToString());
throw new InvalidPluginExecutionException("A problem has occurred. Please press OK to continue using the application.");
}
In your case:
if(responseMessage != null)
{
tracingService.Trace("API call success & got responseMessage.");
}
else
{
tracingService.Trace("responseMessage was empty.");
}
Upvotes: 1