JSON.NET 在 Dynamics CRM 中导致 System.TypeAccessException
JSON.NET causes System.TypeAccessException in Dynamics CRM
当 运行 使用 JSON.NET
将动态对象序列化为 JSON 的自定义工作流操作时,出现以下错误。
在 CRM Dynamics 客户工作流活动/插件中使用反射是否有限制?
是不是因为我使用了dynamic
个变量?
System.TypeAccessException: Attempt by method
'DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure,
System.Runtime.CompilerServices.CallSite, System.Object,
System.String)' to access type
'Newtonsoft.Json.Linq.JObject+JObjectDynamicProxy' failed. at
CallSite.Target(Closure , CallSite , Object , String ) at
WSWA.CRM.Logic.MyobIntegrationLogic.CreateInvoice(Boolean retry) at
WSWA.CRM.Workflows.MyobJob.MyobIntegrationTester.Execute(CodeActivityContext
context)
dynamic account = new JObject();
account.UID = GetAccount("Undeposited Funds Account");
dynamic job = new JObject();
job.UID = GetJob("JFC Interiors");
dynamic gstTaxCode = new JObject();
gstTaxCode.UID = GetTaxUidByCode("GST");
dynamic customer = new JObject();
customer.UID = GetCustomerUid("Bar001.test");
dynamic line1 = new JObject();
line1.Total = 22.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
dynamic line2 = new JObject();
line1.Total = 23.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
var lines = new JArray();
lines.Add(line1);
lines.Add(line2);
dynamic invoice = new JObject();
invoice.Date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
invoice.Customer = customer;
invoice.CustomerPurchaseOrderNumber = "PO Number";
invoice.Number = "INV-1000";
invoice.Lines = lines;
var content = new StringContent(contact.ToString());
content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/json");
var responseTask = httpClient.PostAsync(url, content);
Task.WaitAll(responseTask);
动态类型和使用 Microsoft.AspNet.WebApi.Client 等 NuGet 包存在已知问题。
你能试试 WebClient 吗?
更多信息here
您不能在 Dynamics 中使用 dynamic
类型(讽刺的是不是?)CRM 沙盒插件。您可以使用反射,只要您反射的内容 public 可用。也就是说,您可以使用反射来获取 public 属性的列表,但无法获取私有字段的列表。
您始终可以将您的工作委托给 Azure 服务并在那里做任何您想做的事情。
当 运行 使用 JSON.NET
将动态对象序列化为 JSON 的自定义工作流操作时,出现以下错误。
在 CRM Dynamics 客户工作流活动/插件中使用反射是否有限制?
是不是因为我使用了dynamic
个变量?
System.TypeAccessException: Attempt by method 'DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Object, System.String)' to access type 'Newtonsoft.Json.Linq.JObject+JObjectDynamicProxy' failed. at CallSite.Target(Closure , CallSite , Object , String ) at WSWA.CRM.Logic.MyobIntegrationLogic.CreateInvoice(Boolean retry) at WSWA.CRM.Workflows.MyobJob.MyobIntegrationTester.Execute(CodeActivityContext context)
dynamic account = new JObject();
account.UID = GetAccount("Undeposited Funds Account");
dynamic job = new JObject();
job.UID = GetJob("JFC Interiors");
dynamic gstTaxCode = new JObject();
gstTaxCode.UID = GetTaxUidByCode("GST");
dynamic customer = new JObject();
customer.UID = GetCustomerUid("Bar001.test");
dynamic line1 = new JObject();
line1.Total = 22.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
dynamic line2 = new JObject();
line1.Total = 23.55;
line1.Account = account;
line1.Job = job;
line1.TaxCode = gstTaxCode;
var lines = new JArray();
lines.Add(line1);
lines.Add(line2);
dynamic invoice = new JObject();
invoice.Date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
invoice.Customer = customer;
invoice.CustomerPurchaseOrderNumber = "PO Number";
invoice.Number = "INV-1000";
invoice.Lines = lines;
var content = new StringContent(contact.ToString());
content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/json");
var responseTask = httpClient.PostAsync(url, content);
Task.WaitAll(responseTask);
动态类型和使用 Microsoft.AspNet.WebApi.Client 等 NuGet 包存在已知问题。
你能试试 WebClient 吗?
更多信息here
您不能在 Dynamics 中使用 dynamic
类型(讽刺的是不是?)CRM 沙盒插件。您可以使用反射,只要您反射的内容 public 可用。也就是说,您可以使用反射来获取 public 属性的列表,但无法获取私有字段的列表。
您始终可以将您的工作委托给 Azure 服务并在那里做任何您想做的事情。