C# JSON序列化动态CRM
我试图在自定义活动中用JSON序列化任命 以下是预约课程:C# JSON序列化动态CRM,c#,.net,json,serialization,dynamics-crm-2011,C#,.net,Json,Serialization,Dynamics Crm 2011,我试图在自定义活动中用JSON序列化任命 以下是预约课程: //<summary> // Commitment representing a time interval with start/end times and duration. // </summary> // [System.Runtime.Serialization.DataContractAttribute()] [Microsoft.Xrm.Sdk.Client.EntityLogicalNameAtt
//<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));
}
}
....
在执行活动时,我有以下错误:
插件出现意外异常(执行):
SmartwatchMeeting\u PushGCM.SmartwatchMeeting:
System.Security.SecurityException:数据协定类型
'System.Collections.Generic.KeyValuePair'2[[System.String,mscorlib,
版本=4.0.0.0,区域性=中性,
PublicKeyToken=b77a5csadsad089],[System.Object,mscorlib,
Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5csadsad089]'
无法在部分信任中序列化,因为成员“key”不是
公开的
我不明白我要添加什么才能让它工作
感谢您的帮助您无法序列化类型的非公共成员,因为沙箱强制部分信任,而序列化程序利用反射 您可以:
- 切换到隔离模式:无(仅限本地)
- 为您的数据编写一个仅包含
成员的模型类,并包装记录。这使您的代码更大,但在隔离模式下工作:沙箱public
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());