Problem with WCF and NameValueListBase

Problem with WCF and NameValueListBase

Old forum URL: forums.lhotka.net/forums/t/4254.aspx


skuckreja posted on Tuesday, January 29, 2008

<Serializable()> _

Public Class CSSUserTypeList

Inherits NameValueListBase(Of Integer, String)

#Region " Business Methods "

#End Region

#Region " Factory Methods "

Private Shared mList As CSSUserTypeList

Public Shared Function GetList() As CSSUserTypeList

If mList Is Nothing Then mList = DataPortal.Fetch(Of CSSUserTypeList)(New Criteria(GetType(CSSUserTypeList)))

'If mList Is Nothing Then

' mList = DataPortal.Fetch(Of CSSUserTypeList)()

'End If

Return mList

End Function

Public Shared Sub InvalidateCache()

mList = Nothing

End Sub

Private Sub New()

'required

End Sub

#End Region

#Region " Data Access "

Private Overloads Sub DataPortal_Fetch(ByVal criteria As Criteria)

Me.RaiseListChangedEvents = False

Using cn As New SqlConnection(HSAConnectionString)

cn.Open()

Using cm As SqlCommand = cn.CreateCommand

cm.CommandType = CommandType.StoredProcedure

cm.CommandText = "_NameValueList_Get"

cm.Parameters.AddWithValue("@TableName", "CSSUserType")

Using dr As New SafeDataReader(cm.ExecuteReader)

IsReadOnly = False

With dr

While .Read()

Me.Add(New NameValuePair(.GetInt32("CSSUserTypeID"), .GetString("CSSUserTypeDesc")))

End While

End With

IsReadOnly = True

End Using

End Using

End Using

Me.RaiseListChangedEvents = True

End Sub

#End Region

End Class

I get the error The underlying connection was closed: The connection was closed unexpectedly at the DataPortal.Fetch

I added some tracing and I get the following

Type 'CSSV2.Library.CSSUserTypeList' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.

 

Any help would be appreciated.

RockfordLhotka replied on Wednesday, January 30, 2008

I don't see any obvious issue around serialization...

I'd try running the code with a local data portal, or with remote web debugging enabled, so you can put a breakpoint in DP_Fetch() and see if that code works properly.

Copyright (c) Marimer LLC