gpt4 book ai didi

c# - JSON 序列化 Dynamics CRM

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:55 25 4
gpt4 key购买 nike

我试图在自定义事件中用 JSON 序列化约会。

这是约会类:

//<summary>
// Commitment representing a time interval with start/end times and duration.
// </summary>
//
[System.Runtime.Serialization.DataContractAttribute()]
[Microsoft.Xrm.Sdk.Client.EntityLogicalNameAttribute("appointment")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "7.1.0001.3108")]
public partial class Appointment : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{

// <summary>
// Default Constructor.
// </summary>
public Appointment() :
base(EntityLogicalName)
{
}

public const string EntityLogicalName = "appointment";

public const int EntityTypeCode = 4201;

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;

private void OnPropertyChanged(string propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
....

这是序列化的代码:

Entity entity = (Entity) context.InputParameters["Target"];

ColumnSet csAll = new ColumnSet(true);
Appointment appointment = (Appointment) service.Retrieve(entity.LogicalName, entity.Id, csAll);

System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Appointment));
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, appointment);
string jsonNotification = Encoding.Default.GetString(ms.ToArray());

当事件执行时,出现以下错误:

Unexpected exception from plug-in (Execute): SmartwatchMeeting_PushGCM.SmartwatchMeeting: System.Security.SecurityException: The data contract type 'System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5csadsad089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5csadsad089]]' cannot be serialized in partial trust because the member 'key' is not public

我不明白我必须添加什么才能让它工作?

谢谢你的帮助

最佳答案

您不能序列化类型的非公共(public)成员,因为沙箱强制执行部分信任,并且序列化程序利用反射。

您可以:

  • 切换到隔离模式:无(仅限内部部署)
  • 为您的数据编写一个模型类,只有 public 成员,并包装记录。这会使您的代码更大,但可以在 Isolation mode: Sandbox
  • 下工作

关于c# - JSON 序列化 Dynamics CRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33031870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com