|
Nish Nishant wrote: I vaguely remember when you went past me, think that was quite a few years ago.
Yes, you were actually my inspiration/motivation (I'm quite serious.)
Nish Nishant wrote: An ASP.NET community account is #1?
Yes, but none of those, IMHO, count. They're entities, not people.
Nish Nishant wrote: Maybe the who's who needs an IsIndividualHuman filter
Exactly. But then...
Marc
|
|
|
|
|
Marc Clifton wrote:
Yes, you were actually my inspiration/motivation (I'm quite serious.)
Heh - feels nice to hear that
|
|
|
|
|
He probably meant as an example of bad practices not to follow
|
|
|
|
|
Well, I mean...
|
|
|
|
|
So I got the following declaration in a class:
public class ExpressionModel
{
public static readonly IEnumerable<string> ConditionOperators = new[] { "eq", "neq", "gt", "gte", "lt", "lte", "between" };
} I'm using it in one place as follows:
ExpressionModel.ConditionOperators.Contains(e.Operator) It went well a couple of times and then I got a NullReferenceException on ExpressionModel.ConditionOperators ...
I'm not even sure how ConditionOperators could EVER be null (even if I tried)...
|
|
|
|
|
Are you sure that it was not e.Operator that was null instead? I can hardly imagine how a static variable can lead to a NullReferenceException (since, by design, there is no instance needed).
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
Yep, really sure.
ExpressionModel.ConditionOperators was null, hence the exception when trying to invoke Contains on it.
My first thought was that it should've been e too, but it wasn't.
I actually had it right there in the watch window: ExpressionModel.ConditionOperators: null
|
|
|
|
|
Do you have the problem if you use:
public static readonly List<string> ConditionOperators = new List<string>("eq", "neq", "gt", "gte", "lt", "lte", "between");
instead?
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
Actually I don't have the problem at all anymore. It was a one time thing.
Why do you think the List<string> would be different than IEnumerable<string> string[]?
|
|
|
|
|
Don't know; the use of a fixed, identified type instead of an interface declaration, maybe. But that's really a blind shot.
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
Get LINQPad - The .NET Programmer's Playground[^]
Then add the following code and run it.
Even if e.Operator is set to null (each time x is an odd number) then it never fails.
I blame Visual Studio!!!
void Main()
{
Console.WriteLine(ExpressionModel.ConditionOperators);
for (int x = 0; x<100;x++)
{
Console.WriteLine(ExpressionModel.ConditionOperators.Contains(null));
if (x % 2 == 0)
{
e.Operator = "eq";
}
else{
e.Operator = null;
}
Console.WriteLine(ExpressionModel.ConditionOperators.Contains(e.Operator));
}
}
public static class e{
public static String Operator;
static e()
{
Operator = null;
}
}
public class ExpressionModel
{
public static readonly IEnumerable<string> ConditionOperators = new[] { "eq", "neq", "gt", "gte", "lt", "lte", "between" };
}
Output
5String[] (7 items)4
eq
neq
gt
gte
lt
lte
between
False
True
False
False
False
True
False
False
False
True
...
|
|
|
|
|
Yeah, but e.Operator wasn't the problem
|
|
|
|
|
I know. I was showing that neither the original array was the problem nor the e.Operator was.
There was a question about whether it was null -- so I answered.
|
|
|
|
|
raddevus wrote: There was a question about whether it was null -- so I answered There was a statement that it was null. I'm glad you disagree
|
|
|
|
|
If this was C++, I'd wonder if loop unrolling and parallel execution of the individual loop iterations was happening. That would cause race conditions on the value in e.Operator.
Maybe try rerunning that with affinity set to a single core. Or maybe try it with a Fibonacci computation in the loop -- something whose result depends on inputs from the previous iterations, and therefore prevents loop unrolling and parallel execution.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
Interesting ideas.
|
|
|
|
|
No programming questions in the lounge!
Even if they're Microsoft bug programming questions!
Marc
|
|
|
|
|
Don't you have articles to write?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: Don't you have articles to write?
Marc
|
|
|
|
|
You can kill it with reflection, but that wouldn't happen by accident..
|
|
|
|
|
My cat did walk on the keyboard...
I have a theory that the same happened to Brendan Eich. When he removed the cat from the keyboard something that looked like a language appeared on the screen and thus JavaScript was born. Cats really are evil (yet fluffy and lovable) creatures
|
|
|
|
|
If a cat was involved I'm pretty sure it wasn't by walking on the keyboard. Mistaking it as the litter box OTOH...
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Hey now, my code isn't THAT bad!
|
|
|
|
|
I didn't realize you were one of brendan's pseudonyms...
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Neither did I, who's this Brendan?
|
|
|
|