Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is base..ctor(); in C#?

Tags:

c#

base

I am disassembling some C# applications and I am trying to reconstruct the source code. I am disassembling the application along with the required DLLs.
I keep coming across this line base..ctor(); which gives me an error. The line occurs in some voids with in some subclasses of Stream and Exception.

Does anyone have any idea what the code should be? I am thinking the disassembler messed it up some how and it is clearly invalid code. So does anyone know what it is meant to mean and how I can change the line so it works?

Here is the code of one of the subclasses that line occurs in:

[Guid("ebc25cf6-9120-4283-b972-0e5520d0000E")]
public class ZlibException : Exception
{
    public ZlibException()
    {
        base..ctor();
        return;
    }

    public ZlibException(string s)
    {
        base..ctor();
        return;
    }
}
like image 723
arch Avatar asked Aug 09 '13 15:08

arch


2 Answers

It should be :

[Guid("ebc25cf6-9120-4283-b972-0e5520d0000E")]
public class ZlibException : Exception
{
    public ZlibException() : base()
    {
        return;
    }

    public ZlibException(string s) : base()
    {
        return;
    }
}

Which calls the constructor with that signature on the base implementation of this class.

But by default the .NET CLR calls the base, blank constructor for you, so you don't actually need the : base()

like image 85
joshcomley Avatar answered Sep 23 '22 15:09

joshcomley


It's calling the base constructor, your decompiler is just showing it strangely. In IL, constructors are called .ctor for short, so when directly reading the IL, your decompiler is apparently confused and thinks this is just another method.

The actual code would look like:

public class ZlibException : Exception
{
    public ZlibException() : base();
    {
        return;
    }

    public ZlibException(string s) : base();
    {
        return;
    }
}
like image 40
p.s.w.g Avatar answered Sep 22 '22 15:09

p.s.w.g