MSDN > 論壇首頁 > Visual C# General > Exception Field not found: 'System.Runtime.Serialization.XmlObjectSerializerContext.serializerKnownDataContracts'.
發問發問
 

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

  • Saturday, 14 June, 2008 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

解答

  • Saturday, 14 June, 2008 9:15Calle Mellergardh 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Sorry, but what exactly is the execption (namespace.type) and what is the exact exception message?

    /Calle
    • 已標示為解答Xun Ye Wednesday, 18 June, 2008 2:59
    •  
  • Sunday, 15 June, 2008 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
    • 已提議為解答Shailen Sukul Sunday, 15 June, 2008 0:21
    • 已標示為解答Xun Ye Wednesday, 18 June, 2008 2:59
    •  

所有回覆

  • Saturday, 14 June, 2008 9:15Calle Mellergardh 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Sorry, but what exactly is the execption (namespace.type) and what is the exact exception message?

    /Calle
    • 已標示為解答Xun Ye Wednesday, 18 June, 2008 2:59
    •  
  • Sunday, 15 June, 2008 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
    • 已提議為解答Shailen Sukul Sunday, 15 June, 2008 0:21
    • 已標示為解答Xun Ye Wednesday, 18 June, 2008 2:59
    •