Cannot evaluate expression because the code of the current method is optimized.

S

steevehetu18

Hi,

I'm doing a algorithm to calcule Earliest Start et Latest Start for a
Graph with Nodes and Arcs. (like a PERT diagram) . Unfortunatly, i
receive a wierd exception message for a specific generic (LIST<T>)

This method is calculed often before is put in a foreach statement. At
the first iterration, all is ok. But at the seond, I receive "Cannot
evaluate expression because the code of the current method is
optimized."

His someone can help me ? Here's my code.

Steeve

public void SetEarliestStart()
{
foreach (Node n in _NodeList)
{
n.Visited = false;
n.EarliestStart = 0;
n.Max = 0;
}

//Start Node
_NodeList[0].Visited = true;
_NodeList[0].EarliestStart = 0;

bool AllPrecVisited;
while(_NodeList[_NodeList.Count-1].Visited != true)
{
List<Node> NoneVisitedNodes = new List<Node>();
NoneVisitedNodes = _NodeList.FindAll(delegate(Node
node) //Exception is throw here !!

{

return node.Visited == false;

});
foreach(Node n in NoneVisitedNodes)
{
AllPrecVisited =
n.NodePrecList.TrueForAll(delegate(Node node)

{

return node.Visited == true;

});
if (AllPrecVisited)
{
foreach (Arc a in n.ArcPrecList)
{
if (n.Max < a.NodeStart.EarliestStart +
a.MoveTime
+
a.WorkTime)
{
n.Max = a.NodeStart.EarliestStart +
a.MoveTime + a.WorkTime;
}
}
n.EarliestStart = n.Max;
n.Visited = true;
break;

}
}
}
}
 
D

DaanishRumani

Your Code is set to Optimize. In this mode, the compiler does code
optimizations any can sometimes not be able to debug.

Solution is to disable Optimizations while debugging.
1) Open the project properites from the Solution Explorer by right
clicking and selecting Properties
2) The Project Properties Dialog is shown.
3) Select your configuration from the Configuration Drop Down Box.
4) Under Configuration Properties select Build.
5) Set the Optimize Code drop down to False.
6) Rebuild and then debug.
 
S

Steeve

This property is already to false for my project. Is the problem can
come from another source ?
Can i code my method differently to avoid this error message?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top