当我尝试在 ascx-control 中的类中使用任何扩展方法时:
<%@ Import Namespace="VfmElita.Page.Stat" %>
<%=new MyTestClass().ExtMethod() %>
这是世界上最简单的方法:
namespace VfmElita.Page.Stat
{
public static class TestExtention
{
public static string ExtMethod(this MyTestClass test)
{
return "Hope for result";
}
}
}
(它位于控件的ascx.cs文件中
我收到以下错误:
error CS0012: The type 'System.Xml.IXmlLineInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
如果我用任何属性替换 ExtMethod()
<%= Team.GetTeamById(2).PropOk %>
例如,一切都很好......
为什么?我怎样才能防止这种情况发生?附注问题似乎与 my previous 之一重复或another one 。但当前的更加具体和详细。
附注我尝试手动添加对网站的引用,VisualStuido 告诉我它已经有引用...
最佳答案
听起来您的项目没有对 System.Xml
的引用,并且您在扩展方法的实际实现中使用它。
关于c# - 扩展方法 : IXmlLineInfo 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4680780/