Reputation: 2905
How to resolve 'referenced object has value of nothing' here.....
logDTO object having properties, of type string.
Value of some of the property are empty. it throws the above quoted error. I tried with .ToString() but still throws error.
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; }
}
UPDATE:
Value of logDTO object
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
Upvotes: 0
Views: 3409
Reputation: 67217
Normally .ToString()
function Converts the value of any instance
to its equivalent string
representation. But here your instance
is nothing. That is why it is raising the exception Referenced object has value of nothing
.
I would recommend that you can use Trim()
in your case. It will simply return an empty string
even if the passed argument
is nothing
.
Ex:
trim(logDTO.Mode)
Upvotes: 1