Using .Net 4.5.2 I have the following example code...

var cmd = new SqlCommand();
cmd.Parameters.Add(new SqlParameter("@CONTENTHYPERLINK", SqlDbType.VarChar, 50));
cmd.Parameters["@contentHyperlink"].Value = "hello world";

The third link causes an IndexOutOfRangeException exception

But if I use any of the following (which purely changes the case of the parameter name) it works!

cmd.Parameters["@CONTENTHYPERLINK"].Value = "hello world";
cmd.Parameters["@contenthyperlink"].Value = "hello world";
cmd.Parameters["@contenTHYperlink"].Value = "hello world";

If I use any of the following, it doesn't work...

cmd.Parameters["@contentHyperlink"].Value = "hello world";
cmd.Parameters["@contentHYPERLINK"].Value = "hello world";
cmd.Parameters["@CONTENtHYPERLINK"].Value = "hello world";

(And there are are lots more examples of ones that do and don't work that I won't bother listing here.)

Why on earth does something that should be case-insensitive throw an exception on particular cases?

(I realise the solution to the problem is use one that doesn't cause an exception, but I want to know why this is happening)

  • Does that happen in a new empty project? For me all the examples work as expected in 4.5.2 – Alex K. 4 mins ago
  • @Alex - I'm just trying something similar (an earlier version of the project, where this code has worked for over 10 years without issue) – freefaller 3 mins ago
  • @Alex - sigh... it's working :-( ok, need to figure out what's going on – freefaller 1 min ago

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.