tags:

views:

547

answers:

2

Hi,

I have some code like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save([Bind(Prefix="")]Person person)
{
    String s = person.property;
    /* ... */
}

But it throws the error: "Cannot use local variable 'person' before it is declared".

What simple thing am I missing?

A: 

Okay, this is just some really bizarre error - if the variable is named a particular name it does not work, for any other name it does work...

Graphain
By closing the question, you (and anyone else that comes after) now have no chance of understanding the "really bizarre error", which undoubtedly has a rational explanation.By closing the question you weaken Stackoverflow!Cheers,Rob
Rob
Fair enough, I assumed it was something I was doing specifically wrong and non-applicable to others.
Graphain
A: 

It is most likely that you are receiving this error because the same variable is being declared later in the same code block.

According to compiler rules, a variable reference will refer to default by a matching declaration withing the same block EVEN IF THE SAME DECLARATION EXISTS OUTSIDE OF THE BLOCK IN IN LOGICAL SCOPE FLOW.

So in short, check to see if the variable isnt being declared later on(a couple of lines down) in the same application block.

Yeah I get that, but this was on the first line - the only declaration was a string on said line and the parameter. Still just a rare bug probably related to some weird compilation thing.
Graphain