Bugzilla – Bug 315332
CS0626 is reported when the DllImport attribute is not found
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by vargaz@freemail.hu 2004-07-01 14:44:53 MST ---- When compiling the following test program: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< using System; using System.Text; public class Tests { [DllImport("libglut.so")] public static extern void glutInit(ref int argcp, StringBuilder[] argv); } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< mcs reports: bug-cs0626.cs(7) error CS0626: Method, operator, or accessor 'Tests.glutInit(ref int,System.Text.StringBuilder[])' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation which is a bit confusing, while csc reports the more helpful CS0246: The type or namespace name 'DllImport' could not be found ---- Additional Comments From jluke@cfl.rr.com 2004-07-18 17:12:17 MST ---- Created an attachment (id=166384) attempt at a patch ---- Additional Comments From jluke@cfl.rr.com 2004-07-18 17:13:46 MST ---- The above patch causes the test to print out: $ mcs t.cs t.cs(11) error CS0246: Could not find attribute 'DllImport' (are you missing a using directive or an assembly reference ?) t.cs(11) error CS0246: Could not find attribute 'DllImport' (are you missing a using directive or an assembly reference ?) t.cs(13) error CS0626: Method, operator, or accessor 'Tests.glutInit(ref int,System.Text.StringBuilder[])' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation Compilation failed: 3 error(s), 0 warnings So it is probably not right in that it prints the first error twice, maybe with some help I can figure out the correct fix. ---- Additional Comments From miguel@ximian.com 2004-07-26 12:10:21 MST ---- This is just a side-effect of the order in which we process things: we first do the semantic analysis for the methods, then we do attributes. It is fixable, but will likely require another pass. ---- Additional Comments From rharinath@novell.com 2004-08-02 06:04:57 MST ---- Created an attachment (id=166385) cleanup error messages ---- Additional Comments From rharinath@novell.com 2004-08-02 06:07:26 MST ---- I just added a "complained_before" flag to the Attribute class to fix the double reporting of errors. Basically, 'Type == null' can represent either that the Attribute wasn't resolved, or that resolution was attempted but failed. This clarifies the two cases. Ok to apply? ---- Additional Comments From rharinath@novell.com 2004-08-03 04:24:40 MST ---- Applied to CVS (r=martin) ---- Additional Comments From miguel@ximian.com 2004-08-04 13:53:38 MST ---- This patch is wrong, it now produces errors when compiling Blam for valid code. Download blam-1.2.1.tar.gz to see the problem; Sadly, there is no simple test case for it, the error reported is: Channel.cs(18) error CS0246: Could not find attribute 'XmlAttribute' (are you missing a using directive or an assembly reference ?) Channel.cs(18) error CS8006: Attribute XmlAttribute resolved to different types at different times: vs. System.Xml.Serialization.XmlAttributeAttribute Notice that it has an empty string for the above. Also the patch does not follow the coding conventions: ! complained_before Should be: !complained_before I have reverted this. Notice that this is really a wishlist bug, and there are others that we should probably focus on (Major, Critical, Normal) ---- Additional Comments From jluke@cfl.rr.com 2004-08-31 17:24:46 MST ---- after the commit today to fix, https://bugzilla.novell.com/show_bug.cgi?id=MONO64689 it returns: $ mcs t.cs t.cs(6) error CS0246: Could not find attribute 'DllImport' (are you missing a using directive or an assembly reference ?) t.cs(6) error CS0246: Could not find attribute 'DllImport' (are you missing a using directive or an assembly reference ?) t.cs(8) error CS0626: Method, operator, or accessor 'Tests.glutInit(ref int,System.Text.StringBuilder[])' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation Compilation failed: 3 error(s), 0 warnings which is an improvement in my opinion, but it would be nice to just have one error. I will attach an updated version of raja's patch which fixes this, and compiles, because this bug annoys me. ---- Additional Comments From jluke@cfl.rr.com 2004-08-31 17:26:35 MST ---- Created an attachment (id=166386) updated patch ---- Additional Comments From jluke@cfl.rr.com 2004-09-29 17:05:43 MST ---- *** https://bugzilla.novell.com/show_bug.cgi?id=MONO67149 has been marked as a duplicate of this bug. *** ---- Additional Comments From jluke@cfl.rr.com 2004-09-29 18:19:00 MST ---- Just to clarify my earlier comment, the latest patch reports 1 CS0246 error and 1 CS0626 error, instead of 2 CS0246 errors. It would be best if it did not also report CS0626, but a comment near that error seems to indicate we are more strict on purpose, so I left it alone for now. It also compiles blam, and everything else fine as far as I know. Any chance someone can review/approve/commit this? ---- Additional Comments From rharinath@novell.com 2005-02-22 02:42:58 MST ---- The code in there changed quite a bit. So, the patch, as attached, will not apply. However, I've recently committed a fix that also fixes the double message. So, closing the bug. Imported an attachment (id=166384) Imported an attachment (id=166385) Imported an attachment (id=166386) Unknown operating system unknown. Setting to default OS "Other".