c# - TimeSpan? = DateTime?.Value - DateTime?.Value results in null -
my datetime?
value minus datetime?
value resulting in null timespan?
.
see date values have been pinned debugger.
i not replicate in console app worked same dates. date formats in dd/mm/yyyy
i understand not need .value
code in places. have tried without .value
.
post-edit
timespan ts = datemodified.value - publishrecord.datepublished.value; timespan ts2 = datemodified.value.subtract(publishrecord.datepublished.value); timespan? ts3 = datemodified - publishrecord.datepublished;
all attempts result in line having exception in screenshot. nullable object must have value.
... continuing dig per suggestions , show more information requested...
post-edit 2:
both datemodified , datepublished datetime? standard. properties auto get; set;
post-edit 3 - summary
i can't explain bug. system nunit tested. surprise when in tested area turns up. bug appeared during interface development , debugging attaching class library , refreshing web page. builds in both solutions performed.
i make regular database snapshots , retained current broken 1 while going snapshot prior problem. system worked. going broken 1 showed bug again.
i made console app , wrote code class library reference perform similar code track , not replicate bug in "broken" snapshot.
what happened in between working , not working, windows updates, office software. missed coffee break.
i have retained database snapshot , see if problem occurs again in next few days. if not @ point delete question.
thank attention , suggestions.
there no point in using nullable timespan here in way. either both of datetime?'s have value, , regular (non-nullable) timespan, or 1 or both of datetime?'s not have value, in case access .value
property cause exception. sounds should have code more this:
timespan? ts = null; if (datemodified.hasvalue && publishrecord.datepublished.hasvalue) ts = datemodified.value - publishrecord.datepublished.value;
i noticed this:
i made console app , wrote code class library reference perform similar code track , not replicate bug in "broken" snapshot.
based on that, i'd in thread that's changing 1 of values out under you. perhaps try logging values of datemodified
, publishrecord.datepublished
before line executes , again when exception thrown. expect you'll find 1 of them has become null
.
Comments
Post a Comment