异常描述中存在悖论:Nullable对象必须有一个值(?!)
这就是问题:
我有一个DateTimeExtended
课,有
{
DateTime? MyDataTime;
int? otherdata;
}
Run Code Online (Sandbox Code Playgroud)
和一个构造函数
DateTimeExtended(DateTimeExtended myNewDT)
{
this.MyDateTime = myNewDT.MyDateTime.Value;
this.otherdata = myNewDT.otherdata;
}
Run Code Online (Sandbox Code Playgroud)
运行此代码
DateTimeExtended res = new DateTimeExtended(oldDTE);
Run Code Online (Sandbox Code Playgroud)
抛出一条InvalidOperationException
消息:
可以为空的对象必须具有值.
myNewDT.MyDateTime.Value
- 有效且包含常规DateTime
对象.
这条消息的含义是什么?我做错了什么?
请注意,oldDTE
不是null
.我已经去除了Value
从myNewDT.MyDateTime
,但相同的异常因抛出一个生成的制定者.
Server Error in '/' Application.
--------------------------------------------------------------------------------
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Source Error:
Line 16: HttpContext.Current.RewritePath(Request.ApplicationPath, false);
Line 17: IHttpHandler httpHandler = new MvcHttpHandler();
Line 18: httpHandler.ProcessRequest(HttpContext.Current);
Line 19: HttpContext.Current.RewritePath(originalPath, false);
Line 20: }
Run Code Online (Sandbox Code Playgroud)
我正在关注Steven Sanderson的" Pro …
我正在将一些C#代码转换为Java,我需要包含一个类似于C#的InvalidOperationException的异常.这样的事情存在吗?还有两种语言中的等效异常类型列表吗?谢谢.
我正在实现一个自定义集合实现,可以是readonly或非readonly; 也就是说,所有改变集合的方法都会调用一个与道德相当的函数:
private void ThrowIfReadOnly() {
if (this.isReadOnly)
throw new SomeException("Cannot modify a readonly collection.");
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我不确定应该使用哪种NotSupportedException
或者InvalidOperationException
我应该使用.
.net c# exception invalidoperationexception notsupportedexception
我有一个C#桌面应用程序,其中我创建的一个线程不断从源(实际上是数码相机)获取图像并将其放在GUI中的面板(panel.Image = img)上(必须是另一个线程)它是控件的代码隐藏.
应用程序工作,但在某些机器上,我随机的时间间隔得到以下错误(不可预测)
************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
Run Code Online (Sandbox Code Playgroud)
然后面板变成红十字,红色X - 我认为这是可以从属性中编辑的无效图片图标.应用程序继续工作,但面板永远不会更新.
据我所知,这个错误来自控件的onpaint事件,我在图片上绘制了其他内容.
我尝试使用锁但没有运气:(
我调用将图像放在面板上的函数的方式如下:
if (this.ReceivedFrame != null)
{
Delegate[] clients = this.ReceivedFrame.GetInvocationList();
foreach (Delegate del in clients)
{
try
{
del.DynamicInvoke(new object[] { this,
new StreamEventArgs(frame)} );
}
catch { }
}
}
Run Code Online (Sandbox Code Playgroud)
这是代表:
public delegate void ReceivedFrameEventHandler(object sender, StreamEventArgs e);
public event ReceivedFrameEventHandler ReceivedFrame;
Run Code Online (Sandbox Code Playgroud)
这就是控制代码隐藏中的函数如何注册到它:
Camera.ReceivedFrame +=
new Camera.ReceivedFrameEventHandler(camera_ReceivedFrame);
Run Code Online (Sandbox Code Playgroud)
我也试过了
del.Method.Invoke(del.Target, new object[] { this, new StreamEventArgs(b) });
Run Code Online (Sandbox Code Playgroud)
代替
del.DynamicInvoke(new …
Run Code Online (Sandbox Code Playgroud) 我写了一些MSBuild自定义任务,这些任务运行良好,并在我们的CruiseControl.NET构建过程中使用.
我正在修改一个,并希望通过调用Task的Execute()方法对其进行单元测试.
但是,如果遇到包含的行
Log.LogMessage("some message here");
Run Code Online (Sandbox Code Playgroud)
它会抛出一个InvalidOperationException:
任务尝试在初始化之前进行记录.消息是......
有什么建议?(过去我在自定义任务上主要经过单元测试的内部静态方法,以避免出现此类问题.)
class Program
{
static void Main(string[] args)
{
var dictionary = new Dictionary<string, int>()
{
{"1", 1}, {"2", 2}, {"3", 3}
};
foreach (var s in dictionary.Keys)
{
// Throws the "Collection was modified exception..." on the next iteration
// What's up with that?
dictionary[s] = 1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我完全理解为什么在枚举列表时抛出此异常 - 在枚举期间,枚举对象的结构不会改变似乎是合理的.但是,更改字典的值会改变其结构吗?具体来说,其键的结构?
什么是模拟对于.NET InvalidOperationException
的Python
?
每当我尝试在启用了FIPS的Windows XP计算机上使用MD5时,我都会得到一个System.InvalidOperationException
.
在FIPS上是否应该使用替代算法而不是MD5?
当我使用VSTS调试器来查看类实例的属性时Process
,许多属性都标有InvalidOperationException
.为什么?我做错了吗?
我正在使用VSTS 2008 + C#+ .Net 2.0来开发控制台应用程序.
这是我的代码:
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "IExplore.exe";
myProcess.StartInfo.Arguments = @"www.google.com";
myProcess.StartInfo.Verb = "runas";
myProcess.Start();
Run Code Online (Sandbox Code Playgroud)
以及调试器的屏幕截图:
.net c# process invalidoperationexception visual-studio-2008
c# ×7
.net ×4
exception ×3
asp.net-mvc ×1
cryptography ×1
dictionary ×1
enumeration ×1
gdi+ ×1
java ×1
md5 ×1
msbuild ×1
msbuild-task ×1
nullable ×1
process ×1
python ×1
winforms ×1