Search code examples
c#decompilerc#-10.0

Getting a weird character when decompiling source code


When attempting to decompile an application I'm getting a rectangular box. I'm not sure if there is a way to interpret what this is or not.

 public void Add(MessageErrorCode errorCode);

 public void Add(SegmentErrorContext segmentContext);

 public void AddRange(IEnumerable<MessageErrorCode> errorCodes);

 public void AddRange(IEnumerable<SegmentErrorContext> segmentContexts);

 [IteratorStateMachine(typeof())]
 public IEnumerable<string> Flatten();

 public void Sort();

Solution

  • The IteratorStateMachine attribute is added to the generated IL machine code by the compiler for "iterator" methods that use yield internally.

    You can just remove that attribute for the code to work.

    For illustration look at this SharpLab gist: https://sharplab.io/#gist:fc2cc09bb9cf72774eb724d655613cbf

    The code

    using System;
    using System.Collections.Generic;
    
    public class C 
    {
        public IEnumerable<int> M() 
        {
            yield return 0;
            yield return 1;
        }
    }
    

    is translated into IL Machine Code like this:

    [IteratorStateMachine(typeof(<M>d__0))]
    public IEnumerable<int> M()
    {
        <M>d__0 <M>d__ = new <M>d__0(-2);
        <M>d__.<>4__this = this;
        return <M>d__;
    }