Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JSON序列化动态CRM_C#_.net_Json_Serialization_Dynamics Crm 2011 - Fatal编程技术网

C# JSON序列化动态CRM

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

我试图在自定义活动中用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));
    }
}
....
在执行活动时,我有以下错误:

插件出现意外异常(执行): 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
    成员的模型类,并包装记录。这使您的代码更大,但在隔离模式下工作:沙箱

我使用的是Dynamics CRM Online,因此这将是第二种选择。我必须编辑由CrmSvcUtil生成的类吗?此行[System.Runtime.Serialization.DataContractAttribute()]不允许序列化?谢谢,我肯定更改自动生成的代码会破坏它,但我从未使用过它,所以我不能确定。我建议的是定制包装类。好的,谢谢。问题是我想序列化整个Appointment对象,它相当大。您认为使用Newtonsoft.Json.dll并在之后将其与程序集合并如何?@bidou88值得一试吗?是的,我使用了Newtonsoft.Json,然后将dll与ILMerge合并。它是有效的
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());