Bug 321020 (MONO78279) - [CECIL] cannot compile delegates from different assemblies
Summary: [CECIL] cannot compile delegates from different assemblies
Status: RESOLVED FIXED
Alias: MONO78279
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Linux
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Marek Safar
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-04 11:28 UTC by sagie
Modified: 2011-01-21 15:22 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
FirstClass implementation (128 bytes, text/plain)
2006-05-04 14:55 UTC, Thomas Wiest
Details
SecondClass implementation (279 bytes, text/plain)
2006-05-04 14:55 UTC, Thomas Wiest
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:57:33 UTC


---- Reported by sagie_sh@yahoo.com 2006-05-04 04:28:29 MST ----

Please fill in this template when reporting a bug, unless you know what 
you are doing.
Description of Problem:
I have two different assemblies. In the first I created a function with
a delegate as parameter. In the second I call to that function. The 
compiler won't receive it.

Steps to reproduce the problem:

In First.Dll:
   namespace FirstNS
   {
      class FirstClass
      {
         public delegate void MyDlgt();

         public void Foo(MyDlgt){}
      }
   }

In Second.dll:

   using FirstNS;
   namespace SecondNS
   {
      class SecondClass
      {
         public void Operation()
         {
            FirstClass fc = new FirstClass();
            FirstClass.MyDlgt dlgt = new FirstClass.MyDlgt(DoNothing);
            fc.Foo(dlgt);
         }

         public void DoNothing(){}
      }
   }
Actual Results:
Second.dll won't compile - error CS1503: cannot convert from 
FirstClass.MyDlgt to FirstClass.MyDlgt

Expected Results:
Compile normally

How often does this happen? 
every time

Additional Information:



---- Additional Comments From rharinath@novell.com 2006-05-04 06:38:49 MST ----

Firstly, please don't set the Priority or Severity flags of a bug,
unless you know what they mean.  This is not a blocker.

Secondly, your sample code doesn't demonstrate the problem.  I cannot
reproduce it with the sample code as is, nor with the obvious fix to
make 'FirstClass' public.



---- Additional Comments From sagie_sh@yahoo.com 2006-05-04 07:55:05 MST ----

Created an attachment (id=169735)
FirstClass implementation




---- Additional Comments From sagie_sh@yahoo.com 2006-05-04 07:55:51 MST ----

Created an attachment (id=169736)
SecondClass implementation




---- Additional Comments From sagie_sh@yahoo.com 2006-05-04 07:56:23 MST ----

I have some more details:
In my project, I have loop reference - second.dll refers to First.dll,
and First.dll refers to Second.dll. In addition, MyDlgt is defined in 
SeconClass. I have added the two classes as attachments.

Imported an attachment (id=169735)
Imported an attachment (id=169736)
Comment 2 Marek Safar 2007-11-05 12:13:54 UTC
How am I suppose to build your sample if they have circular dependency ?
Comment 3 Gert Driesen 2007-11-10 20:12:02 UTC
I managed to reproduce the issue by compiling in the following order:
1) compile Second.dll without dependencies on First.dll
2) compile First.dll referencing Second.dll
3) compile Second.dll with dependencies on First.dll

This results in the following errors:

second.cs(15,25): error CS1502: The best overloaded method match for `FirstNS.FirstClass.Foo(SecondNS.SecondClass.MyDlgt)' has some invalid arguments
second.cs(15,25): error CS1503: Argument 1: Cannot convert type `SecondNS.SecondClass.MyDlgt' to `SecondNS.SecondClass.MyDlgt'

If you have NAnt installed, then you can use this standalone repro:
gert/standalone/bug321020 in SVN
Comment 4 Marek Safar 2008-07-22 15:25:57 UTC
After some investigation this should be possible to implement with SRE. When fixing this by doing string comparison in TypeManager::IsEqual (Type a, Type b) we still end up we 2 different tokens for same type (it crashes .NET and it creates invalid assembly with 2 references to same type on Mono).

What actually happen is that we have 2 types of same type. One is TypeBuilder and (created) second one is Type (imported). They are same but Equals returns false.

The correct fix would be to redirect imported type to current type but that is big change which probably has to wait for CECIL.

One indication is warning CS1683 which csc reports when change seconds.cs namespace.

first.dll: warning CS1683: Reference to type 'SecondNS.SecondClass' claims it is
        defined in this assembly, but it is not defined in source or any added
        modules
second.cs(17,4): error CS0570: 'Foo' is not supported by the language
first.dll: (Location of symbol related to previous error)
Comment 5 Marek Safar 2011-01-21 15:22:02 UTC
Fixed in master