Search code examples
c#.netextension-methods

Problem with Extension method: IXmlLineInfo


When I try to use any extension method to my class in ascx-control:

<%@ Import Namespace="VfmElita.Page.Stat" %>
<%=new MyTestClass().ExtMethod() %>

and here is the simplest method in the world:

namespace VfmElita.Page.Stat
{
public static class TestExtention
{
    public static string ExtMethod(this MyTestClass test)
    {
        return "Hope for result";
    }
}
}

(it is located in ascx.cs-file of the control

I got the following error:

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'.

If I replaced ExtMethod() with any property

<%= Team.GetTeamById(2).PropOk %>

for example, everything is fine...

Why? How can I prevent this?

P.S. It seems like question is duplicate to one of my previous or another one. But the current one is more specific and pretty detailed.

P.S. I've tried to add reference to web-site manually, VisualStuido tells that it has reference already...


Solution

  • I don't know what is a source of such strange behavior... everything is fine with this Extension Method... answer for another question resolved current question too.