.Net Extension Method (this string Foo) Only Partially Visible

走远了吗. 提交于 2019-12-01 18:03:22

In web.config, try adding to the system.web/pages/namespaces node

<system.web>
    ....
    <pages ....>
        ....
        <namespaces>
            ....
            <add namespace="MyApp.Extensions" />

You will also need to ensure that the ASP.NET compiler is in 3.5 mode:

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
              type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <providerOption name="CompilerVersion" value="v3.5"/>
      <providerOption name="WarnAsError" value="false"/>
    </compiler>
 </compilers>
</system.codedom>

Your web site is running with .Net 2.0 and it does not support extention method/class. so .NET 2.0 compiler treated it as normal static method. it will compile in .net 3.5 only

I would never recommend keeping Extension methods inside any namespace.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!