Question

I am having the following error for my WCF Client:

"Error in line 1 position 1910. Element 'http://schemas.datacontract.org/2004/07/SubSonic:_currentValue' contains data of the 'http://schemas.datacontract.org/2004/07/System:DBNull' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'DBNull' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer."

I am using Subsonic 2.0 for generating my class objects.

I have also decorated my class and members using DataContract and DataMember.

Have tried adding [KnownType(typeof(System.DBNull))] to my Generated class.

Have tried adding [ServiceKnownType(typeof(System.DBNull))] to my Service Interface.

My generated class looks like: (This class is generated for SQL View)

/// <summary>
    /// This is  Read-only wrapper class for the  view.
    /// </summary>
    [Serializable]    
    [KnownType(typeof(System.DBNull))]
    [DataContract]
    public partial class VwPatientRt : ReadOnlyRecord<VwPatientRt> 
    { ... ...

Service Interface:

 [ServiceContract]    
    [ServiceKnownType(typeof(System.DBNull))]    
    public interface IPatientService
    {
        [WebInvoke(Method = "GET", UriTemplate = "GetPatientAppointments")]
        [OperationContract]
        IList<VwPatientRt> GetPatientAppointments();
     ..... 

Service Class :

public class PatientService : IPatientService
{ 
    public IList<VwPatientRt> GetPatientAppointments()
    {
       ... .
       .....
    }
   ... 

At client side everything seems ok. Because for other methods and classes it is working fine.

On looking with detailed exception DBNull and _currentValue is used in Subsonic TableColumnSetting class.

What should i do?

Have also googled and gone through similar posts but none helped me and have struggling from almost 2 days on this.

Any help or suggestion with code snippet is appreciated.

:Solved:

My WCF service was build using framework 4.5 and my consuming client was build using framework 3.5. Due to this Add Service Reference wizard was not generating Class attribute for KnownTypes which were declared using

[ServiceKnownType(typeof(System.DBNull))] 

So, when deserializing client was not getting System.DBNull type. We have to add knowntypes in clients config file.

This Configuration needed at client side which solved my problem:

<system.runtime.serialization>
        <dataContractSerializer>    
            <declaredTypes>
                <add type="NameSpace.ServiceClientName.ClassNameForWhichKnownTypeIsToBeGiven, AssemblyName">
                    <knownType  type="System.DBNull"></knownType>
                </add>
             </declaredTypes>
        </dataContractSerializer>
</system.runtime.serialization> 

Hope this will be useful for someone.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top