Answered by:
WCF and System.Runtime.Serialization error

Question
-
User811304085 posted
I changed from web refrence to service refrence in .Net 3.5, as a result it updated refrence.cs
I am calling a wcf service and getting the following error. Before this this was working fine
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyServiceWcf" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost.parksell.pvt/MyService/MyServiceWcf.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyServiceWcf"
contract="MyService.IMyServiceWcf" name="WSHttpBinding_IMyServiceWcf">
<identity>
<servicePrincipalName value="host/localhost.PARKSELL.PVT" />
</identity>
</endpoint>
</client>
</system.serviceModel>Project1.Framework.RequestController.RequestConfigurationInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)
at System.Runtime.Serialization.DataContract.CheckAndAdd(Type type, Dictionary`2 typesChecked, Dictionary`2& nameToDataContractTable)
at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContractsForKnownTypes(IList`1 knownTypeList)
at System.Runtime.Serialization.DataContractSerializer.get_KnownDataContracts()
at System.Runtime.Serialization.XmlObjectSerializerContext..ctor(DataContractSerializer serializer, DataContract rootTypeDataContract)
at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex..ctor(DataContractSerializer serializer, DataContract rootTypeDataContract)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.CreateContext(DataContractSerializer serializer, DataContract rootTypeDataContract)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(Stream stream, Object graph)
at ASSET.Framework.Util.Serialize[T](T objectToSerialize)Wednesday, April 10, 2013 10:33 PM
Answers
-
User-1818759697 posted
Hi,
When applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer. Here is an example shows a type to which the DataContractAttribute and DataMemberAttribute attributes have been applied:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx
For further information, you could access to the below links:
http://stackoverflow.com/questions/4575783/is-this-a-serialisation-error-or-a-data-contract-error
Regards
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 12, 2013 1:22 AM
All replies
-
User-917364509 posted
Project1.Framework.RequestController.RequestConfigurationInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
Add a [DataContract] attribute to your RequestConfigurationInfo and a [DataMember] attribute to the properties you wish to serialize. You can read more here: http://msdn.microsoft.com/en-us/library/ms733127.aspx.
Thursday, April 11, 2013 5:14 AM -
User-448512826 posted
add corresponding attribute in your service...
resolved thread here
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/d6e20aa1-2313-450f-bc36-d9ebcb087f6e
Thursday, April 11, 2013 5:24 AM -
User811304085 posted
I am direclty accessing the property in reference.cs, where should I make [DataContract] , [DataMember] to resolve the issue
client.cs
User GetUser(XmlNode node)
{
User user = new User();
foreach (XmlNode userNode in node)
{
switch (userNode.Name)
{
case "AdminType":
user.AdminType = ConvertToInt(userNode.InnerText,0);
break;
case "Email":
user.Email = ConvertToString(userNode.InnerText);
break;
case "FirstName":
user.FirstName = ConvertToString(userNode.InnerText);
break;
case "LastName":
user.LastName = ConvertToString(userNode.InnerText);
break;
case "LanguageCode":
user.LanguageCode = ConvertToString(userNode.InnerText);
break;
case "UserGuid":
if (ConvertToString(userNode.InnerText) != string.Empty)
{
user.UserGuid = new Guid(ConvertToString(userNode.InnerText));
}
break;
case "abc":
abc abc = new abc();
foreach (XmlNode abcNode in userNode)
{
switch (abcNode.Name)
{
case "SetupQuestionsDisplayed":
abc.SetupQuestionsDisplayed = ConvertToString(abcNode.InnerText);
break;
case "ClientTypeID":
abc.ClientTypeID = ConvertToInt(abcNode.InnerText,0);
break;
}}
user.abc = abc;
break;
case "RMSUserCode":
user.RMSUserCode = ConvertToInt(userNode.InnerText,0);
break;
case "DataClients":
DataClient dataClient = new DataClient();
foreach (XmlNode dataClientNode in userNode)
{
//Some work
}
DataClient[] dataClients = {dataClient};
user.DataClients = dataClients;
break;
}
}
return user;
}/*************************************/
Reference.cs
Part of Reference.cs
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="User", Namespace="http://Test.net")]
[System.SerializableAttribute()]
public partial class User : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Test.Security.Agent.MyService.MysClient MyClientField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.Nullable<int> AdminTypeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Test.Security.Agent.MyService.DataClient[] DataClientsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string EmailField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string FirstNameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string LanguageCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string LastNameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Test.Security.Agent.MyService.User ManagementUserField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string PasswordField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.DateTime PasswordModifiedDateField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Test.Security.Agent.MyService.Role[] RolesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.DateTime USerStatusModifiedDateField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private byte[] UserRowVersionField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Test.Security.Agent.MyService.EnumsUserStatus UserStatusCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string UsernameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.Guid UserGuidField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int RMSUserCodeField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Test.Security.Agent.MyService.MysClient MysClient {
get {
return this.MysClientField;
}
set {
if ((object.ReferenceEquals(this.MysClientField, value) != true)) {
this.MysClientField = value;
this.RaisePropertyChanged("MysClient");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Nullable<int> AdminType {
get {
return this.AdminTypeField;
}
set {
if ((this.AdminTypeField.Equals(value) != true)) {
this.AdminTypeField = value;
this.RaisePropertyChanged("AdminType");
}
}
}Thursday, April 11, 2013 3:42 PM -
User-1818759697 posted
Hi,
When applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer. Here is an example shows a type to which the DataContractAttribute and DataMemberAttribute attributes have been applied:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx
For further information, you could access to the below links:
http://stackoverflow.com/questions/4575783/is-this-a-serialisation-error-or-a-data-contract-error
Regards
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 12, 2013 1:22 AM