Microsoft 开发人员网络 > 论坛主页 > Visual C# General > Exception Field not found: 'System.Runtime.Serialization.XmlObjectSerializerContext.serializerKnownDataContracts'.
提出问题提出问题
 

已答复Exception Field not found: 'System.Runtime.Serialization.XmlObjectSerializerContext.serializerKnownDataContracts'.

  • 2008年6月14日 0:45HydPhani 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     包含代码
    Hi All, 

        I am calling a business layer method call as below: 

    List<UsageCategorySummary> prodUsageCategorySummary = ProductDomain.Instance.GetUsageCategories();

    hidUsageCategory.Value = this.JsonSerializerHelper(prodUsageCategorySummary);


    Helper function code 

    private string JsonSerializerHelper(System.Object objRef)

    {

    string result = string.Empty;

    using (MemoryStream memoryStream = new MemoryStream())

    {

    DataContractJsonSerializer serializer = new DataContractJsonSerializer(objRef.GetType());

    // Resulting to an exception...

    // //  Exception Field not found: 'System.Runtime.Serialization.XmlObjectSerializerContext.serializerKnownDataContracts'.
    serializer.WriteObject(memoryStream, objRef);
    memoryStream.Position = 0;

    using (StreamReader streamReader = new StreamReader(memoryStream))

    {

    result = streamReader.ReadToEnd();

    }

    }

    return result;

    }

    Exception occurring at the above colored line... any thoughts?!


    HydPhani

答案

  • 2008年6月14日 9:15Calle Mellergardh 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Sorry, but what exactly is the execption (namespace.type) and what is the exact exception message?

    /Calle
    • 已标记为答案Xun Ye 2008年6月18日 2:59
    •  
  • 2008年6月15日 0:21Shailen Sukul 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
     Seems like your object cannot be serialized. This can happen if you have a child List collection.
    See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=302308&SiteID=1

    Please remember to mark as answered. -- With Regards Shailen Sukul (Shane) Software Architect/Developer/Consultant/Trainer (BSc | Mct | Mcpd | Mcts (Sharepoint (IP), Biztalk, Web, Win, Dist Apps) | Mcsd.NET | Mcsd | Mcad) Ashlen Consulting Services Pty Ltd (http://www.ashlen.com.au) MSN | Skype | GTalk Id: shailensukul Ph: +61 421 277 812 Fax: +61 3 9011 9732 Blog: http://shailensukul.blogspot.com

全部回复

  • 2008年6月14日 9:15Calle Mellergardh 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Sorry, but what exactly is the execption (namespace.type) and what is the exact exception message?

    /Calle
    • 已标记为答案Xun Ye 2008年6月18日 2:59
    •  
  • 2008年6月15日 0:21Shailen Sukul 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
     Seems like your object cannot be serialized. This can happen if you have a child List collection.
    See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=302308&SiteID=1

    Please remember to mark as answered. -- With Regards Shailen Sukul (Shane) Software Architect/Developer/Consultant/Trainer (BSc | Mct | Mcpd | Mcts (Sharepoint (IP), Biztalk, Web, Win, Dist Apps) | Mcsd.NET | Mcsd | Mcad) Ashlen Consulting Services Pty Ltd (http://www.ashlen.com.au) MSN | Skype | GTalk Id: shailensukul Ph: +61 421 277 812 Fax: +61 3 9011 9732 Blog: http://shailensukul.blogspot.com