如何在这里解决'引用对象没有价值'.....
logDTO对象具有string类型的属性。
部分财产的价值是空的。它抛出上面引用的错误。我尝试使用.ToString()但仍然会抛出错误。
Public Sub WriteJobLog(ByVal logDTO As JobLogDTO)
Dim strArray As String() = {logDTO.Mode.ToString(), logDTO.UniqueId.ToString(), logDTO.ThreadId.ToString(), _
logDTO.StartTime.ToString(), logDTO.FinishTime.ToString(), logDTO.TimeTaken.ToString(), _
logDTO.PropertyId.ToString(), logDTO.ChannelId.ToString(), logDTO.URL.ToString(), _
logDTO.ExceptionOrResult.ToString(), logDTO.AvblWorkerThread.ToString(), logDTO.AvblPortThread.ToString(), _
logDTO.AcqrdWorkerThread.ToString(), logDTO.AcqurdPortThread.ToString(), logDTO.JobsToProcess.ToString()}
Dim lLogObj As Logging = New Logging(JobType.JOB_TRANSACTTIONAL)
lLogObj.WriteLogFile(String.Join(Configuration.LogDelimiter, strArray))
End Sub
JobLogDTO
public class JobLogDTO
{
public string Mode { get; set; }
public string UniqueId { get; set; }
public string ThreadId { get; set; }
public string StartTime { get; set; }
public string FinishTime { get; set; }
public string TimeTaken { get; set; }
public string PropertyId { get; set; }
public string ChannelId { get; set; }
public string URL { get; set; }
public string ExceptionOrResult { get; set; }
public string AvblWorkerThread { get; set; }
public string AvblPortThread { get; set; }
public string AcqrdWorkerThread { get; set; }
public string AcqurdPortThread { get; set; }
public string JobsToProcess { get; set; }
}
更新:
logDTO对象的值
AcqrdWorkerThread "24" String
AcqurdPortThread "24" String
AvblPortThread "400" String
AvblWorkerThread "399" String
ChannelId Nothing String
ExceptionOrResult Nothing String
FinishTime Nothing String
JobsToProcess "24" String
Mode "Parallel" String
PropertyId Nothing String
StartTime "04.04.2013 12:17:25" String
ThreadId "5" String
TimeTaken Nothing String
UniqueId "97693c1b-2bbc-4e40-a542-291568aeee4c" String
URL Nothing String
答案 0 :(得分:1)
通常.ToString()
函数将任何instance
的值转换为其等效的string
表示。但在这里你的instance
一无所获。这就是为什么它会引发异常Referenced object has value of nothing
。
我建议您在案例中使用Trim()
。即使传递的empty string
为argument
,它也只会返回nothing
。
<强>实施例强>
trim(logDTO.Mode)