.NET decompiled assembly has an '&' after the type producing build error

957 views Asked by At

I have inherited a few assemblies which as far as I know were produced using Visual Studio 2005, .NET Framework 1.1(?), and VB.NET. Unfortunately, the source code is no longer available to me. As a result, I have used dotPeek to decompile the assemblies (as C#) and attempt to reverse engineer the projects. The resulting source code has a few lines that look similar to:

// ISSUE: explicit reference operation
// ISSUE: variable of a reference type
string& szDataDescr = @str;

The 'string&' is foreign to me (and Visual Studio too apparently). Visual Studio 2015 is not recognizing this as valid, and I am getting compilation errors. Is the '&' something that dotPeek has added, or is it some legacy .NET construct that was valid way back then? Similar comment appears everywhere the 'type&' pattern is used, so I assume it is associated.

1

There are 1 answers

0
Kees C. Bakker On BEST ANSWER

The & sign after a type name indicates that it's a reference type, and the @ before a variable name generates a reference to that variable.

If you tried to compile the code, you'll get an error because the compiler treats & as the bitwise and, and will complain that you used a type as if it were a variable. But that's ok because you didn't get it from a C# source file.

Best solution is to use a different decompiler.

Check here for more info on what the & does in IL.