简体   繁体   中英

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));

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM