简体   繁体   中英

Cannot create an instance of the abstract class or interface 'System.Drawing.Image'

Image img = new Image();
img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next();  
    // added random for caching issue.
this.Controls.Add(img);

I get the error as

Cannot create an instance of the abstract class or interface 'System.Drawing.Image' --->Line 1

'System.Drawing.Image' does not contain a definition for 'ImageUrl' and no extension method 'ImageUrl' accepting a first argument of type 'System.Drawing.Image' could be found (are you missing a using directive or an assembly reference?) ---> Line2

The best overloaded method match for 'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid arguments ---> Line3

Error 10 Argument '1': cannot convert from 'System.Drawing.Image' to 'System.Web.UI.Control'

Please help me to solve the error.

It looks like you're trying to use the wrong Image class. Fully qualify it and it should work like you're expecting.

  System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
    img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next();  // added random for caching issue.
    this.Controls.Add(img);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM