0

如何在这里解决“引用的对象没有任何价值”.....
logDTO 对象具有字符串类型的属性。
一些属性的值是空的。它抛出上面引用的错误。我尝试使用 .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

作业日志DTO

   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
4

1 回答 1

1

通常.ToString()function 将 any 的值转换instance为其等效string表示。但在这里你instance什么都不是。这就是它引发异常的原因Referenced object has value of nothing

我建议您可以Trim()在您的情况下使用。empty string即使传递argument的是,它也会简单地返回一个nothing

前任:

trim(logDTO.Mode)
于 2013-04-04T07:03:16.583 回答