代码之家  ›  专栏  ›  技术社区  ›  Tim Hutchison

无法在插件注册工具中调试Dynamics C#插件

  •  2
  • Tim Hutchison  · 技术社区  · 6 年前

    背景

    我在Dynamics 2016中有一个C#插件,它使用一个库来调用其他系统。该库的一部分是使用Web API调用dynamics。插件正在采取行动,因为我可以看到动态的变化,但我希望它采取不同的行动,而不是采取。当我尝试使用插件注册工具调试插件时,遇到了一些问题。当我使用Exception方法分析插件时,我得到了一个异常文件,可以调试到一定程度。当我得到下面的代码,插件注册工具崩溃,没有一个错误消息。当我使用Persist to Entity方法进行调试时,我的插件似乎成功了,但是插件注册工具中没有记录配置文件。我的插件是从一个动作触发的,该动作是从附加到业务流程流完成的工作流触发的(这是基于 this 条款)。我的第一个问题是 here 这就引出了这个问题。想让调试器使用我的代码吗?

    代码

    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;
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Arun Vinoth-Precog Tech - MVP    6 年前

    我记得这个问题,当我调试SharePoint online REST API调用时,它总是会崩溃。然后我添加了跟踪服务和日志检查点来验证代码执行路径。我将下载Profiler trace log&replay in PRT以查看成功或失败分支,而不是进行调试。

    当您将插件跟踪配置为日志时 全部 在“系统设置”下,它的开发模式将非常有用。

                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.");
    
                }
    

    Reference

    就你而言:

                if(responseMessage != null)
                {
    
                    tracingService.Trace("API call success & got responseMessage.");
    
                }
                else
                {
    
                    tracingService.Trace("responseMessage was empty.");
    
                }