“Cannot obtain value of local or argument” “as it is not available at this instruction pointer, possibly because it has been optimized away.”
8 May 2008 – 18:27
Welcome in the weird world of C#! Sometimes you say: “Programming is simply, if you know how things work then you can debug or fix every problems!”. But when something not understandable happens, well… you just have your eyes to cry!
In my case I was doing a small part of code, following a tutorial. Everything was crystal clear. But at the execution, this error happened:
Cannot obtain value of local or argument XXXXX as it is not available at this instruction pointer, possibly because it has been optimized away.
So I began to search, and it was honestly the first time that the Microsoft search engine gave me more answer than Google! And what a surprise when I discovered that all the occurrence found were people that had this problem and that the problem was completely different from mine. Going further, I discovered that in the most cases, having this exception is a known problem of the framework: I couldn’t do nothing about it.
So basicaly, it is a weakness in the .NET 2.0 framework. Don’t ask me more, people from who i got the intell didn’t knew much more. but since my speciality is to be stubborn I tried a few things and found something that could interest you if you are in the same case.
In fact, when you execute the line of code that returns this exception, it is like it is executed 2 times so a solution is to surround your code by this:
Try{
Your_expression;
}
catch{Exception}
Your expression will be evaluated and will return the exception but with no effect. Ok, it is quick and dirty but it works, and can help you if like me, you don’t have a choice.
If you have any feedback about that issue, please leave a comment!!!

2 Responses to ““Cannot obtain value of local or argument” “as it is not available at this instruction pointer, possibly because it has been optimized away.””
Dirty, Dirty, and very effective. Thanks for the post.
By ClubbieTim
on Jan 19, 2010
err..Quick, Dirty, and very effective….
By ClubbieTim
on Jan 19, 2010