mscorlib.ni.dll中出现类型“System.InvalidOperationException”的异常,但未处理 [英] Exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll but was not handled

查看:412
本文介绍了mscorlib.ni.dll中出现类型“System.InvalidOperationException”的异常,但未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下消息:

mscorlib.ni.dll中出现System.InvalidOperationException类型的异常,但未在用户代码中处理

"Exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll but was not handled in user code"

当我的TimePicker没有任何时间选择为空时,会出现此问题。

This problem occurs when my TimePicker dont have any time choosen when I leave it empty.

我的TimePicker的代码看起来像这样;

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.

任何想法?

**

推荐答案

如果 startBreak1.Value 是一个字符串:

if (startBreak1!= null) 
    DateTime.TryParse(startBreak1.Value, out break1S);

如果它是一个 Nullable< DateTime> 我认为是这样)

if it's a Nullable<DateTime> (and I think it is)

DateTime break1S = startBreak1.HasValue 
                          ? startBreak1.Value
                          : new DateTime()//or anything you want;

或接受 break1S 可以为空:

var break1S = startBreak1;

这篇关于mscorlib.ni.dll中出现类型“System.InvalidOperationException”的异常,但未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆