Arun
Arun

Reputation: 1017

CompilationRelaxations attribute not working

I have a simple console application in .net 4.5.

public class Program
{
    public static void Main()
    {
        string s1 = "s1";
        string s2 = "s1";

        Console.WriteLine(ReferenceEquals(s1, s2));
    }
}

This gives true because of string interning. However, when I add the CompilationRelaxations attribute to the AssemblyInfo file, I'm still seeing true as the output.

[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]

Even adding the attribute to my Program class does not seem to change the output. [CompilationRelaxations(CompilationRelaxations.NoStringInterning)]

Changing it to a .net 4.0 application does not have any effect either.

What am I missing?

Upvotes: 0

Views: 281

Answers (1)

Vyacheslav Volkov
Vyacheslav Volkov

Reputation: 4742

Here is a quote from the documentation:

Marks an assembly as not requiring string-literal interning.

It doesn't prevent the compiler from doing string interning, just providing a hint that it's not required. The documentation for it is quite poor, both in MSDN and the CLI spec. See also this MSDN forum post.

Upvotes: 1

Related Questions