Bug 9944 - Mono.CSharp.Evaluator: x.GetType throws NotSupported Exception
Summary: Mono.CSharp.Evaluator: x.GetType throws NotSupported Exception
Status: NEW
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2013-01-31 11:00 UTC by lukebuehler
Modified: 2015-11-06 10:25 UTC (History)
2 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description lukebuehler 2013-01-31 11:00:33 UTC
Description of Problem:
Getting the Type of an instance (x.GetType) of a class that has be defined in the evaluator itself throws an exception.

Steps to reproduce the problem:
This is regarding Mono 3.0.3: Mono.CSharp.Evaluator, 
I'm running Windows 7 x64 and .NET and use only a reference to Mono.CSharp.dll. It seems to be only a problem on .NET

When I instantiate an Evaluator and then then evaluate following input:

    var context = new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter());
    var evaluator = new Evaluator(context);
    evaluator.DescribeTypeExpressions = true;

    object result = null;
    bool set = false;
    evaluator.Evaluate("class A{ public int X;}", out result, out set);

    //this works
    evaluator.Evaluate("var a = new A();a.GetType();", out result, out set);

    //this doesnt work
    evaluator.Evaluate("var a = new A();", out result, out set);
    //Error here:
    evaluator.Evaluate("a.GetType();", out result, out set);

I get an error in the second last line:
System.IO.FileNotFoundException: Could not load file or assembly 'eval-0, Version=, Culture=neutral, PublicKeyToken=null' o
r one of its dependencies. The system cannot find the file specified.
File name: 'eval-0, Version=, Culture=neutral, PublicKeyToken=null'
   at <InteractiveExpressionClass>.Host(Object& $retval)
   at Mono.CSharp.Evaluator.Evaluate(String input, Object& result, Boolean& result_set)
   at MonoEval.Program.Main(String[] args) in C:\Users\Luke\Dev\Samples\MonoEval\Program.cs:line 30

=== Pre-bind state information ===
LOG: User = wall-e\Luke
LOG: DisplayName = eval-0, Version=, Culture=neutral, PublicKeyToken=null
LOG: Appbase = file:///C:/Users/Luke/Dev/Samples/MonoEval/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Luke/Dev/Samples/MonoEval/bin/Debug/eval-0.DLL.
LOG: Attempting download of new URL file:///C:/Users/Luke/Dev/Samples/MonoEval/bin/Debug/eval-0/eval-0.DLL.
LOG: Attempting download of new URL file:///C:/Users/Luke/Dev/Samples/MonoEval/bin/Debug/eval-0.EXE.
LOG: Attempting download of new URL file:///C:/Users/Luke/Dev/Samples/MonoEval/bin/Debug/eval-0/eval-0.EXE.

Additional Information:
Discussion here:
Comment 1 Marek Safar 2013-02-04 09:59:36 UTC
This looks like another SRE .NET bug

The exception thrown is actually: Field not found: '<InteractiveExpressionClass>.a'.

Which is odd and when executed as generated set of 3 dlls everything works as expected. I have also tried to change codegen to use closed type and field instead of typebuilder/fieldbuilder but no change.
Comment 2 lukebuehler 2013-02-04 12:57:26 UTC
What is a SRE .NET bug. Is there anything I can do about it? Does this lie on the MSFT side?

I'm building an elaborate scripting & data analysis project, which I plan to open source. But this bug is really holding me down because I'm trying to define data types and then for example plot the data using reflection. But right now this is not possible.

Interestingly anonymous types work, this works being evaluated separately: 
   var x = new {n=10, i=100};
Comment 3 Marek Safar 2013-02-04 14:01:10 UTC
Yes, it's possibly SRE .NET bug but I didn't try to create simple repro.

The scenario is

Define a type in assembly A
Define another type in assembly B with field of type A
Define another type in assembly C with access to field from type in assembly B

When using dynamic assemblies (AssemblyBuilder) .NET fails to find the field.

Anonymous type works because you are using it from same or second assembly.

Note You need to log in before you can comment on or make changes to this bug.