问题
I am getting this message:
"Exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll but was not handled in user code"
This problem occurs when my TimePicker dont have any time choosen when I leave it empty.
My code for the TimePicker looks like this;
DateTime break1S = (DateTime)startBreak1.Value;
Its on this row i am getting the message but if i set a time for the picker i dont get an message.
Any ideas?
**
回答1:
If startBreak1.Value
is a string :
if (startBreak1!= null)
DateTime.TryParse(startBreak1.Value, out break1S);
if it's a Nullable<DateTime>
(and I think it is)
DateTime break1S = startBreak1.HasValue
? startBreak1.Value
: new DateTime()//or anything you want;
or accept that break1S
can be nullable :
var break1S = startBreak1;
回答2:
The solution look like this:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
回答3:
you can try this:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
来源:https://stackoverflow.com/questions/16893855/exception-of-type-system-invalidoperationexception-occurred-in-mscorlib-ni-dll