Bug 8607 - First extension method is ignored when using Mono.CSharp.Evaluator.
Summary: First extension method is ignored when using Mono.CSharp.Evaluator.
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2012-11-26 23:38 UTC by Jason Heddings
Modified: 2013-10-07 11:24 UTC (History)
1 user (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jason Heddings 2012-11-26 23:38:49 UTC
It appears that the first extension method is not being recognized when using the Mono.CSharp compiler as a service.

Here is the sample code I have been testing with:

public static class Program {
    public static void Main(String[] args) {
        CompilerSettings sett = new CompilerSettings();
        ReportPrinter prnt = new ConsoleReportPrinter();
        CompilerContext ctx = new CompilerContext(sett, prnt);
        Evaluator eval = new Evaluator(ctx);

        eval.Run(@"using System;");
        eval.Run(@"public static class first_ext {
            public static void try_one(this object obj) {
                Console.WriteLine(""try one"");
        }");  // no compiler error
        eval.Run(@"DateTime.Now.try_one();");  // error: "try_one" does not exist
        eval.Run(@"public static class second_ext {
            public static void try_two(this object obj) {
                Console.WriteLine(""try two"");
        }");  // no compiler error
        eval.Run(@"DateTime.Now.try_two();");  // prints "try two"

Using Mono 3.0.1 downloads on both Windows 7 and Mac OS X (10.8)
Comment 1 Jason Heddings 2012-11-26 23:41:22 UTC
Specific output:

2012-11-26 21:39:07
(1,15): error CS1061: Type `System.DateTime' does not contain a definition for `try_one' and no extension method `try_one' of type `System.DateTime' could be found. Are you missing an assembly reference? C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll (Location of the symbol related to previous error)
try two
Comment 2 Marek Safar 2013-02-04 10:02:40 UTC
I cannot reproduce it with the latest Mono
Comment 3 Marek Safar 2013-10-07 11:24:40 UTC
Closing as fixed