开发者

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开发者_StackOverflow.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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜