[英]An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll but was not handled in user code: in Xamarin Form
[英]Exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll but was not handled
我收到此消息:
“ mscorlib.ni.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理 ”
当我的TimePicker留空时,没有选择任何时间时,会发生此问题。
我的TimePicker代码如下所示;
DateTime break1S = (DateTime)startBreak1.Value;
它在这一行上我收到消息,但是如果我为选择器设置时间,则不会收到消息。
有任何想法吗?
**
如果startBreak1.Value
是一个字符串:
if (startBreak1!= null)
DateTime.TryParse(startBreak1.Value, out break1S);
如果它是Nullable<DateTime>
(我认为是)
DateTime break1S = startBreak1.HasValue
? startBreak1.Value
: new DateTime()//or anything you want;
或接受break1S
可以为空:
var break1S = startBreak1;
解决方案如下所示:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
您可以尝试以下方法:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.