【问题标题】:Cannot create an instance of the abstract class or interface 'System.Drawing.Image'无法创建抽象类或接口“System.Drawing.Image”的实例
【发布时间】:2011-05-12 10:54:07
【问题描述】:
Image img = new Image();
img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next();  
    // added random for caching issue.
this.Controls.Add(img);

我得到的错误是

无法创建抽象类或接口'System.Drawing.Image'的实例--->第1行

“System.Drawing.Image”不包含“ImageUrl”的定义,并且找不到接受“System.Drawing.Image”类型的第一个参数的扩展方法“ImageUrl”(您是否缺少 using 指令或汇编参考?)---> Line2

'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' 的最佳重载方法匹配有一些无效参数 ---> Line3

错误 10 参数“1”:无法从“System.Drawing.Image”转换为“System.Web.UI.Control”

请帮我解决错误。

【问题讨论】:

  • 尝试用普通大写而不是全部大写来发布问题。看起来有人在喊
  • @haris 抱歉,我的大写锁定在我输入所有内容后才注意到

标签: c# asp.net


【解决方案1】:

您似乎在尝试使用错误的 Image 类。完全限定它,它应该像你期望的那样工作。

  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);

【讨论】:

    猜你喜欢
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    相关资源
    最近更新 更多