469,610 Members | 1,762 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

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

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<NodeNoneVisitedNodes = 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;

}
}
}
}

Sep 4 '06 #1
2 15505
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.
st**********@hotmail.com wrote:
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<NodeNoneVisitedNodes = 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;

}
}
}
}
Sep 5 '06 #2
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.
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.
Sep 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John A Grandy | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.