c# - 扩展方法 : IXmlLineInfo 出现问题

标签 c# .net extension-methods

当我尝试在 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/

相关文章:

c# - 解析和验证手机号码的最佳实践

C#并行,如何设置线程数

c# - 嵌套循环不进入每个元素c#

c# - Action 延迟扩展方法不起作用

c# - 业务对象,在线对象和计算器上 - 这是最好的

c# - 通用接口(interface)和扩展方法发现的多个实现

.net - 什么是 "web services"?

asp.net - 将 background-url css 属性设置为 .net 中的内存图像

c# - 在静态上下文中调用 C# 扩展方法是否有效?

c# - 计算 IEnumerable 的计数(非通用)