标签: argumentexception

无效的回发或回调参数.使用'<pages enableEventValidation ="true"/>'启用事件验证

当我从客户端发回页面时,我收到以下错误.我有JavaScript代码修改客户端的asp:ListBox.

我们如何解决这个问题?

错误详情如下:

Server Error in '/XXX' Application.

--------------------------------------------------------------------------------
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Description: An unhandled exception occurred …
Run Code Online (Sandbox Code Playgroud)

.net asp.net postback argumentexception .net-2.0

233
推荐指数
14
解决办法
59万
查看次数

如何检查数据表中是否存在列

我有一个使用csv文件内容生成的数据.我使用其他信息将csv的某些列(现在在数据表中)映射到用户需要填充的信息.

在最好的世界中,映射总是可能的.但这不是现实......所以在我尝试映射数据表列值之前,我需要检查该列是否存在.如果我不这样做,请检查我是否有ArgumentException.

当然我可以用这样的代码来检查:

try
{
    //try to map here.
}
catch (ArgumentException)
{ }
Run Code Online (Sandbox Code Playgroud)

但我现在有3列要映射,部分或全部可能存在/缺失

有没有一种好方法可以检查数据表中是否存在列?

c# datatable argumentexception

83
推荐指数
4
解决办法
19万
查看次数

"参数无效"异常加载System.Drawing.Image

为什么我的代码中出现"参数无效"异常:

MemoryStream ms = new MemoryStream(byteArrayIn);
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
Run Code Online (Sandbox Code Playgroud)

长度byteArrayIn是169014.尽管事实上它没有大于255的值,但我得到了这个例外.

c# image stream argumentexception

30
推荐指数
5
解决办法
11万
查看次数

字体'Times New Roman'不支持'Regular'风格

有人听说过这个吗?System.ArgumentException:字体'Times New Roman'不支持样式'Regular'.

我有一个通过ClickOnce部署的WinForms应用程序.由于某些原因,许多用户收到此错误.我可以看到因为选择非标准字体而出现此错误,但Times New Roman,Regular?是否有人们需要的服务包或其他东西?

我很想听听已经找到解决这个问题的人的消息.

.net fonts argumentexception winforms

12
推荐指数
2
解决办法
1万
查看次数

在添加项目时,在ConcurrentDictionary <TKey,TValue>上调用ToList()

我遇到了一个有趣的问题.知道ConcurrentDictionary<TKey, TValue>在被修改时安全可枚举,(在我的情况下)迭代可能消失或多次出现的元素的不必要的副作用,我决定自己创建一个快照,使用ToList().既然ConcurrentDictionary<TKey, TValue>也实现了ICollection<KeyValuePair<TKey, TValue>>,这会导致List(IEnumerable<T> collection)使用它Count,然后使用当前项目在字典的当前大小中创建一个数组,然后尝试复制项目using ICollection<T>.CopyTo(T[] array, int arrayIndex),调用它的ConcurrentDictionary<TKey, TValue>实现,最后抛出一个ArgumentExceptionif元素被添加在此期间到字典.

全部锁定会破坏使用集合的重点,所以我的选择似乎是继续捕获异常并重试(这绝对不是问题的正确答案),或者实现我自己的ToList()专用版本对于这个问题(但是再一次,简单地增加一个列表然后可能将其修剪为适合几个元素的大小似乎是一种过度杀伤,并且使用LinkedList会降低索引性能).

此外,似乎添加某些LINQ方法在后台创建某种缓冲区(例如OrderBy)似乎以性能为代价来修复问题,但裸露ToList()显然没有,并且它不值得"扩充"当不需要其他功能时,使用另一种方法.

这可能是任何并发收集的问题吗?

在创建此类快照时,将性能命中率降至最低的合理解决方法是什么?(最好在一些LINQ魔法结束时.)

编辑:

在调查之后,我可以确认,ToArray()(我认为我昨天刚刚通过它)确实解决了快照问题,只要它只是一个简单的快照,在拍摄快照之前需要额外的功能时它没有帮助(例如过滤,排序),最后还需要一个列表/数组.(在这种情况下,需要额外调用,重新创建新集合.)

我没有指出快照可能需要也可能不需要经过这些修改,所以应该在最后进行,最好是,所以我将这个添加到问题中.

(另外,如果有人对标题有更好的想法,请告诉.)

.net linq argumentexception tolist concurrentdictionary

12
推荐指数
1
解决办法
1144
查看次数

Marshal.PtrToStructure抛出System.ArgumentException错误

我试图从键盘钩子的lParam获取KBDLLHOOKSTRUCT.

    private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
    {

        KBDLLHOOKSTRUCT kbd = new KBDLLHOOKSTRUCT();
        Marshal.PtrToStructure(lParam, kbd); // Throws System.ArguementException
        ...
Run Code Online (Sandbox Code Playgroud)

不幸的是,PtrToStructure正在投掷两个

A first chance exception of type 'System.ArgumentException' occurred in myprogram.exe
Run Code Online (Sandbox Code Playgroud)

每次按下一个键都会出错.它也会阻止该方法的发展.

MSNDA说:http: //msdn.microsoft.com/en-us/library/4ca6d5z7.aspx

ArgumentException when:

The structureType parameter layout is not sequential or explicit.

-or-

The structureType parameter is a generic type.
Run Code Online (Sandbox Code Playgroud)

我能在这做什么才能让它发挥作用?lParam直接来自键盘钩子,所以我希望它是正确的.这些错误中的任何一个都有意义吗,我该怎么做才能解决它?

c# marshalling argumentexception

10
推荐指数
1
解决办法
2万
查看次数

InvalidOperationException与ArgumentException

我知道摘要和说明.

但是如果ARGUMENT处于无效状态怎么办?

我认为ArgumentException更合适,因为InvalidOperationException文档说该方法被调用的对象必须处于无效状态.这有意义吗?

c# invalidoperationexception argumentexception

10
推荐指数
1
解决办法
2211
查看次数

为什么FormatException不从ArgumentException继承?

有没有已知的原因FormatException不继承ArgumentException?无效格式似乎是一个非常具体的参数无效的情况,类似于ArgumentOutOfRangeException.

该类MSDN文章指出:

当方法调用中的参数格式与相应的形式参数类型的格式不匹配时,抛出FormatException.例如,如果方法指定一个String由两个带嵌入句点的数字组成的参数,则将只包含两位数的相应字符串参数传递给该方法将导致抛出FormatException.

听起来像是ArgumentException我的一个或派生课程的场景.

所有这些意味着您无法FormatException在较大的ArgumentException异常系列下处理,也无法识别导致异常的参数.

这个看似不合时宜的例外是否有任何理由存在?

.net exception argumentexception formatexception

9
推荐指数
2
解决办法
964
查看次数

为什么ArgumentNullException?为什么不System.NullReferenceException?

请参阅以下代码行:

DataTable [] _tables = null;

// Throws System.NullReferenceException
_tables.GetType();

// Throws System.ArgumentNullException
_tables.Count();
Run Code Online (Sandbox Code Playgroud)

在这行代码中我_tables引用并试图访问它的系统定义函数,GetType()并且Count()都抛出异常,但为什么.Count()抛出System.ArgumentNullException,因为我们有相同的参考值,是null什么?

c# argumentexception nullreferenceexception

8
推荐指数
2
解决办法
1018
查看次数

无效参数对的异常

当同时给出的参数无效时,接受多个参数的方法应该抛出哪个异常?

作为一个例子,考虑

public Bar DoSomething(Foo f1, Foo f2)
{
  //implementation...
}
Run Code Online (Sandbox Code Playgroud)

完成操作取决于f1和之间的某种关系或相似性f2(如果是数组/集合,它们必须具有相同的大小;如果是运动员,它们必须属于同一团队/对手团队;等等)。

每个参数都是该操作的有效参数,但它们一起无效。例子:

public MatchResult PlayMatch(Player a, Player b)
{
  if(a.Team == b.Team)
  {
    //Throw exception here, since players must be on different teams
  }

  //Play match, determine winner
}
Run Code Online (Sandbox Code Playgroud)

抛出一个ArgumentException似乎不正确,因为它意味着其中一个参数无效,而不是一对参数一起无效。

c# arguments exception argumentexception

7
推荐指数
1
解决办法
1084
查看次数