Working on moving one of our projects from inproc to using SOSS and ran into some errors that indicated some of our models/dtos needed to be serializable. For all but one of these, adding
[Serializable()]
to the top of the class resolved all issues. For the remaining one, it is now returning this error:
System.Exception: An service exception has occured the exception was System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetAllAttachmentsResult. The InnerException message was 'Error in line 1 position 686. 'EndElement' 'YourDTO' from namespace 'http://schemas.datacontract.org/2004/07/Business.Objects.Message' is not expected. Expecting element '_x003C_AttachmentDate_x003E_k__BackingField'.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: Error in line 1 position 686. 'EndElement' 'YourDTO' from namespace 'http://schemas.datacontract.org/2004/07/Business.Objects.Message' is not expected. Expecting element '_x003C_AttachmentDate_x003E_k__BackingField'.
Here is the DTO:
namespace Business.Objects.Message
{
[Serializable()]
public class YourDTO
{
public long Id { get; set; }
public FileType Type{ get; set; }
public string Name { get; set; }
public DateTime AttachmentDate { get; set; }
public string UserName { get; set; }
public YourDTO()
{
Id = 0;
Name = string.Empty;
Type = FileType.Unknown;
AttachmentDate = DateTime.MinValue;
UserName = string.Empty;
}
}
}
The code that uses this simply populates the DTO from a db as a DataTable and then sends back the list of DTOs after mapping.
Couple things to note:
- This DTO is passed through a nuget package to the solution in question.
- I did try [DataContract] as well but this did not work either.
- This has worked for years up to this point. Only change is adding SOSS to web.config for SessionState and the [Serializable() attribute addition.
Any ideas would be greatly appreciated!