BUG OF THE MONTH | Replacement That Did Not Work

private static void WriteSimpleValue(ITextOutput output,
                                     object value, string typeName)
  switch (typeName)
    case "string":
      output.Write(  "'"
                   + DisassemblerHelpers
                      .Replace("'", "\'")                   
                   + "'");
    case "type":

V3038 The ‘”‘”‘ argument was passed to ‘Replace’ method several times. It is possible that other argument should be passed instead. ICSharpCode.Decompiler ReflectionDisassembler.cs 772

The author seems to be replacing all single quote character occurrences with a string consisting of two characters: a backslash and a single quote character. However, the developer missed a beat and by accident replaced the “‘” with itself, thus performing a meaningless operation. There is no difference between assigning a string variable a value of “‘” or “\'” – either way the string is initialized with a single quote character. To include “\'” in a string, use escape characters: “\\'” or @”\'”. Thus, one can change the Replace method call in the following way:

Replace("'", @"\'")

Please click here to see more bugs from this project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.