Questions tagged [argumentexception]

An ArgumentException is a specific exception in the .NET framework thrown when one of the arguments provided to a method is not valid.

From MSDN:

ArgumentException is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method.

232 questions
252
votes
40 answers

Invalid postback or callback argument. Event validation is enabled using ''

I am getting the following error when I post back a page from the client-side. I have JavaScript code that modifies an asp:ListBox on the client side. How do we fix this? Error details below: Server Error in '/XXX'…
Julius A
  • 38,062
  • 26
  • 74
  • 96
126
votes
8 answers

How to check if a column exists in a datatable

I have a datable generated with the content of a csv file. I use other information to map some column of the csv (now in the datatable) to information the user is required to fill. In the best world the mapping would be alway possible. But this is…
Rémi
  • 3,867
  • 5
  • 28
  • 44
42
votes
9 answers

"Parameter not valid" exception loading System.Drawing.Image

Why am I getting the exception "Parameter not valid" in my code: MemoryStream ms = new MemoryStream(byteArrayIn); System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms); The length of byteArrayIn is 169014. I am getting this…
manoj
14
votes
2 answers

InvalidOperationException vs. ArgumentException

I know the summaries and descriptions. But what if the ARGUMENT is in an INVALID STATE? I think the ArgumentException is more appropriate because the InvalidOperationException documentation says that the object on what the method is called itself…
timmkrause
  • 3,367
  • 4
  • 32
  • 59
14
votes
3 answers

Font 'Times New Roman' does not support style 'Regular'

Anybody hear of this one? System.ArgumentException: Font 'Times New Roman' does not support style 'Regular'. I've got a WinForms app that is deployed via ClickOnce. For some reason a number of users are getting this error. I can see getting this…
Brian
  • 37,399
  • 24
  • 94
  • 109
13
votes
1 answer

Marshal.PtrToStructure throwing System.ArgumentException error

I'm attempting to get a KBDLLHOOKSTRUCT from a keyboard-hook's lParam. private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { KBDLLHOOKSTRUCT kbd = new KBDLLHOOKSTRUCT(); Marshal.PtrToStructure(lParam,…
ck_
  • 3,719
  • 10
  • 49
  • 76
10
votes
4 answers

How to Compare strings in Linq Query

CompareTo is not working here for me. My linq query is var result = from c in customers where c.CustomerID.CompareTo(txtSerchId.Text) >= 0 select` c; and em getting an…
MBasit
  • 101
  • 1
  • 1
  • 4
9
votes
2 answers

Why does FormatException not inherit from ArgumentException?

Is there a known reason why FormatException does not inherit from ArgumentException? An invalid format would seem to be a very specific case of an argument being invalid, similar to ArgumentOutOfRangeException. The MSDN article for the class…
Paul Turner
  • 38,949
  • 15
  • 102
  • 166
8
votes
2 answers

ArgumentNullException message without parameter name

I am throwing ArgumentNullException in part of my code in C#. I want to catch and display the error message of my exception. But without the parameter name. I want to pass the parameter name to the exception constructor. throw new…
filipv
  • 314
  • 1
  • 3
  • 15
8
votes
4 answers

Why ArgumentNullException? Why not System.NullReferenceException?

See line of code below: DataTable [] _tables = null; // Throws System.NullReferenceException _tables.GetType(); // Throws System.ArgumentNullException _tables.Count(); In this lines of code I have _tables reference and trying to access its system…
Ankush Madankar
  • 3,689
  • 4
  • 40
  • 74
7
votes
1 answer

C# - How do I find why an ArgumentException is occurring?

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll Additional information: Parameter is not valid. This is happening at the end of this code. public void WriteStatusMessage(string message) { …
Sean Duggan
  • 1,105
  • 2
  • 18
  • 48
7
votes
3 answers

What is the difference between ArgumentException and just Exception?

In our professor's example code he has one snippet that looks like this: if (name == null || name == "") throw new ArgumentException("name is null or empty"); And another snippet that looks like this: if (!File.Exists(name)) { throw new…
pkerts
  • 93
  • 1
  • 5
7
votes
2 answers

an Interesting Exception While get an Image from Internet

I am developing a program in WPF, getting a picture from the web and used an image control. My image list has 50 pictures (from vimeo's thumbnails). Everything looks fine but number 45. The picture has some problem and when I get to the 45th…
unbalanced
  • 1,192
  • 5
  • 19
  • 44
6
votes
5 answers

RegEx -- Quantifier {x,y} following nothing error

I am very new to RegEx -- so can someone please help me figure out what exactly is going wrong here? I have this code: string regPattern = "*[~#%&*{}/<>?|\"-]+*"; string replacement = ""; Regex regExPattern = new…
yeahumok
  • 2,940
  • 19
  • 52
  • 63
6
votes
1 answer

StrongNameKeyPair problem when attempting to use MoQ

I'm trying to create a mock HttpContextBase for unit test. var fakePrinciple = new GenericPrincipal( new GenericIdentity(userId), rolesList.ToArray()); var mockHttpContext = new…
Rokey Ge
  • 681
  • 8
  • 18
1
2 3
15 16