ETSample1_CS: Unhandled Exception: System.InvalidOperationException

Dec 31, 2008 at 11:28 AM

Greetings,

Please find appended below the said exception.

Did I miss something in my environment for this sample to work correctly?

BTW, is Expression.Assign an undocumented feature?


Regards,

hph


PS D:\DLR\Codeplex-DLR-0.9\Bin\Debug> .\ETSample1_CS
What is the name of the star you are currently orbiting?
sun
What is the numer of the planet, counting from the sun, you are currently at?
3

Unhandled Exception: System.InvalidOperationException: Variable 'StarName' referenced from lambda 'lambda_method', but it is not defined in an outer scope
   at Microsoft.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression variable, Boolean hoist) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\VariableBinder.cs:line 201
   at Microsoft.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\VariableBinder.cs:line 209
   at Microsoft.Linq.Expressions.ParameterExpression.Accept(ExpressionTreeVisitor visitor) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ParameterExpression.cs:line 55
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.Visit(Expression node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 35
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.VisitAssignment(AssignmentExpression node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 130
   at Microsoft.Linq.Expressions.AssignmentExpression.Accept(ExpressionTreeVisitor visitor) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\AssignmentExpression.cs:line 60
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.Visit(ReadOnlyCollection`1 nodes) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 41
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.VisitBlock(Block node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 150
   at Microsoft.Linq.Expressions.Block.Accept(ExpressionTreeVisitor visitor) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\Block.cs:line 38
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.Visit(ReadOnlyCollection`1 nodes) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 41
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.VisitBlock(Block node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 150
   at Microsoft.Linq.Expressions.Block.Accept(ExpressionTreeVisitor visitor) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\Block.cs:line 38
   at Microsoft.Linq.Expressions.ExpressionTreeVisitor.Visit(Expression node) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\ExpressionTreeVisitor.cs:line 35
   at Microsoft.Linq.Expressions.Compiler.VariableBinder.Bind() in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\VariableBinder.cs:line 94
   at Microsoft.Linq.Expressions.Compiler.VariableBinder.Bind(CompilerScope parent, Expression scope) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\VariableBinder.cs:line 79
   at Microsoft.Linq.Expressions.Compiler.LambdaCompiler.AnalyzeLambda(LambdaExpression lambda) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\LambdaCompiler.cs:line 257
   at Microsoft.Linq.Expressions.Compiler.LambdaCompiler.CompileLambda(LambdaExpression lambda, Type delegateType, Boolean emitDebugSymbols, Boolean forceDynamic, MethodInfo& method) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\LambdaCompiler.cs:line 176
   at Microsoft.Linq.Expressions.Compiler.LambdaCompiler.CompileLambda(LambdaExpression lambda, Boolean emitDebugSymbols
) in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Compiler\LambdaCompiler.cs:line 207
   at Microsoft.Linq.Expressions.LambdaExpression.Compile() in D:\DLR\Codeplex-DLR-0.9\Runtime\src\Microsoft.Scripting.Core\Ast\LambdaExpression.cs:line 104
   at ETSample1_CS.Program.Main(String[] args) in D:\DLR\Codeplex-DLR-0.9\Samples\ExpressionTree\ETSample1_CS\Program.cs
:line 37
PS D:\DLR\Codeplex-DLR-0.9\Bin\Debug>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Dec 31, 2008 at 5:14 PM
This appears to be a bug in the sample.  Please file a bug report under "Issues".  You can make the sample work by changing the last line of the NotSoSimpleHelloWorld sample. The first "Block" should actually be a "Scope" -- that would make the line read "return Expression.Scope(Expression.Block(Instructions), StarName, PlanetNumber);"

What do you mean by "undocumented feature" with respect to Expression.Assign?  One particular overload is missing an XML comment, but it has the same meaning as the other overload, whose comment reads "Performs an assignment variable = value".
Dec 31, 2008 at 7:47 PM
Greetings,

> From: CurtHagenlocher
> This appears to be a bug in the sample. Please file a bug report under "Issues".

I am surprised that this bug escaped the QA cycle.

> You can make the sample work by changing the last line of the NotSoSimpleHelloWorld sample.
> The first "Block" should actually be a "Scope" -- that would make the line read
> "return Expression.Scope(Expression.Block(Instructions), StarName, PlanetNumber);"

Yes, that works. Thank you.

> What do you mean by "undocumented feature" with respect to Expression.Assign?

It's not in VS2008 Documentation.

Your help is really appreciated.


Happy New Year.

PhiHo
Dec 31, 2008 at 7:56 PM
> I am surprised that this bug escaped the QA cycle.

The "Block" and "Scope" functionality is being merged between DLR 0.9 and DLR 1.0.  I'd guess that the author tested against the newer sources without checking to see that they would also work for 0.9.  Our QA doesn't always cover source code samples for community releases, and the samples aren't part of our continuous integration.  The DLR code itself has extensive test coverage.

> It's not in VS2008 Documentation.

This is unsurprising given that the functionality didn't exist at the time VS2008 was released.  The DLR contains "version 2" of the expression trees that are in .NET 3.5, so you'll probably find other example that aren't in the 3.5 documentation.  Rest assured, they'll be part of the .NET 4.0 documentation once it's released.
Jan 7, 2009 at 9:53 PM
The Block factory changed at a point to have the ParameterExpressions as the first argument. The sample code for the current DLR version should read (Program.cs, Line 101):

return Expression.Block(new ParameterExpression[] { StarName, PlanetNumber }, Expression.Block(Instructions));

The change should be propagated to CodePlex over the next week.