-
-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Description
See #438 for the context
When the last statement in a TryCatch block is a goto and the label is on the outside, we encounter an System.InvalidProgramException: Common Language Runtime detected an invalid program. error. We haven’t been able to find a reliable workaround for this yet.
// FEC throws `System.InvalidProgramException: Common Language Runtime detected an invalid program.`
var label = Label( "label" );
var variable = Variable( typeof( int ), "variable" );
var block = Block(
[variable],
TryCatch(
Block(
Assign( variable, Constant( 5 ) ),
Goto( label )
),
Catch(
typeof( Exception ),
Block(
typeof( void ),
Assign( variable, Constant( 10 ) )
)
)
),
Label( label ),
variable
);
var lambda = Lambda<Func<int>>( block );
Additionally we also found that when the label is moved into the same scope as the goto we get System.ArgumentException: Bad label content in ILGenerator.
// FEC throws `System.ArgumentException: Bad label content in ILGenerator.`
var label = Label( "label" );
var variable = Parameter( typeof( int ) );
var exceptionParam = Parameter( typeof( Exception ), "ex" );
var block = Block(
[variable],
TryCatch(
Block(
Goto( label ),
Throw( Constant( new Exception( "Exception" ) ) ),
Label( label ),
Assign( variable, Constant( 2 ) )
),
Catch( exceptionParam, Assign( variable, Constant( 50 ) ) )
),
variable
);
var lambda = Lambda<Func<int>>( block );
var compiledLambda = lambda.CompileFast();