Я использую Enterprise library 5.0, фактически, блок протоколирования. В некоторых случаях я могу обращаться ниже за исключением, если соединение с удаленной конечной точкой не преуспевающее:Невозможно лишить System.Collections.Hashtable в виде System.Collections.Generic.IDictionary
Public Function Connect(ByVal sender As Socket) As Integer
Dim result As Integer
result = -1
Try
' Connect the socket to the remote endpoint.
sender.Connect(remoteEP)
Logger.Write("Socket connected to remote endpoint {0}", _
sender.RemoteEndPoint.ToString())
result = 0
Catch ... another exception
Catch ... another exception
Catch ex As System.Net.Sockets.SocketException
Using New Tracer(Common.LOGGING_SOCKETCONNECTIONERROR)
Dim contextInfo As IDictionary = New Hashtable()
contextInfo.Add("Additional Info (Stack Trace)", ex.StackTrace)
Dim provider As DebugInformationProvider = New DebugInformationProvider()
provider.PopulateDictionary(contextInfo)
Dim logEntry As LogEntry = New LogEntry()
logEntry.Categories.Add(Common.LOGGING_CRITICAL_ERRORS_CATEGORY)
logEntry.Message = String.Format("An error occurred when attempting to access the socket: {0}", ex.Message)
logEntry.ExtendedProperties = contextInfo
Logger.Write(logEntry)
End Using
End Try
Return result
End Function
Когда над исключением обжигает я получаю ошибку преобразования в строке:
provider.PopulateDictionary(contextInfo)
Ошибка преобразования заключается в следующем :
System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Collections.Hashtable' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'."
Что я делаю неправильно?
Является ли ваша функция PopulationDictionary ожидающей IDictionary или IDictionary (из TKey, TValue)? Он должен ожидать, что IDictionary я считаю –
ну, PopulateDictionary имеет следующую подпись: Public Sub PopulateDictionary (ByVal dict As System.Collections.Generic.IDictionary (Of String, Object)) – user1624552
и contextInfo - это Hashtable, реализующая System.Collection.IDictionary. .. Поэтому измените подпись вашей функции, и все должно работать нормально ... –