Bugzilla – Bug 321020
[CECIL] cannot compile delegates from different assemblies
Last modified: 2011-01-21 15:22:02 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)
How am I suppose to build your sample if they have circular dependency ?
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
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)
Fixed in master