Search code examples
c#decompiling

"Cannot find extension method" error occurs when decompiling C# assembly


Because of the needs of the project, I need to decompile the C# assembly. Using Relector on the recommendation of a colleague Here is an example:

  internal class WebTreeDialogPage : WebXmlHttp2Page
  {
      public WebTreeDialogPage()
      {
          this.Source = new EasySearch2DataSet();
          base.Style = PageStyle.Custom;
          base.Operation = "TreeExpand";
      }

      protected override void DoPost()
      {
          base.DoPost();
          this.GetXsltFile();
          base.Response.ContentEncoding = Encoding.UTF8;
          string content = this.Transform.TransformContent(base.IsIe);
          if (AppSettings.Current.Debug)
          {
              FileUtil.SaveFile(AppSettings.Current.XmlPath + "EasySearch.html", content);
          }
          base.Response.Write(content);
      }
  }

Decompiled code base.Response.ContentEncoding = Encoding.UTF8 Why is there an error in Encoding.UTF8, suggesting that "string" does not contain the definition of "UTF8".

And there are "Cannot find extension method 'UTF8' that accepts a first argument of type 'string' (are you missing a using directive or an assembly reference)"


Solution

  • This means that there's a property (or field) string Encoding on WebXmlHttp2Page.

    Change the code to use System.Text.Encoding.UTF8.