Why do I get a "Compiler Error Message: CS1002: ; expected" error message at site?

Works fine at my dev. PC, However once I run it on the site I get:

Compiler Error Message: CS1002: ; expected

byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);

var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };

var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
Jon Skeet
people
quotationmark

You'll get this if you're using a machine that only has .NET 2.0 or .NET 3.0 installed, and thus only a C# 2 compiler.

This code:

var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, ... };

... uses an object initializer which was introduced into C# 3. (It also uses var, which was introduced at the same time.)

I suspect you just need to upgrade your web site to a more recent version of .NET.

You could validate that this is the problem by simply having a statement of:

var x = "";

I suspect you'll find that fails with an error that the compiler can't find the var type - whereas the C# 3+ compiler will use implicit typing instead.

people

See more on this question at Stackoverflow