Search code examples
c#.netdotpeek

Decompiled DLL - CS1660 Cannot convert to 'Delegate' because type is not of delegate type


I decompiled a .net 4.6.1 project dll with dotpeek. After decompiling I have the following error:

CS1660 Cannot convert to 'Delegate' because type is not of delegate type

private void MainLogAdd(string s, System.Drawing.Color color)
    {
      this.logcol.Add(color);
      this.lstLogBox.Invoke((delegate) (() =>
      {
        this.lstLogBox.Items.Add((object) ("[" + DateTime.Now.TimeOfDay.ToString().Substring(0, 8) + "] " + s));
        this.lstLogBox.TopIndex = this.lstLogBox.Items.Count - 1;
      }));
    }

After change with new Action 'Action 1 does not contain a constructor that takes its arguments' '


Solution

  • I believe it'll work out if you simply change (delegate) to (Action) instead

    Before:

    this.lstLogBox.Invoke((delegate) (() =>
    

    After:

    this.lstLogBox.Invoke((Action) (() =>
    

    Here's an example:

    enter image description here

    Edit

    You say you have a class called Action already and it's causing a conflict. You can use the full name:

    this.lstLogBox.Invoke((System.Action) (() =>
    

    Or you can create an alias by e.g. putting this at the top of your class:

    using SystemAction = System.Action;
    

    Then using the alias..

    this.lstLogBox.Invoke((SystemAction) (() =>
    

    Or you can rename your class :)