0

this is my problem with VS :S in the first project : System.Security.Cryptography.AesCryptoServiceProvider obj;
everything is ok
in the second project:
System.Security.Cryptography.AesCryptoServiceProvider obj1;
it doesn't recognize the AesCryptoServiceProvider?!!

is VS using different packages or what ?!

updated: changed the variable name but still not working

Katia
  • 679
  • 2
  • 15
  • 42
  • Are you including the references to the appropriate dll in each project? – Jason Oct 30 '11 at 19:15
  • @Jason no I didn't . but I didn't for both of the projects, how come one of them works yet the other doesn't ! what reference should I add ? – Katia Oct 30 '11 at 19:18
  • 1
    Both are using same .net version? – Akash Kava Oct 30 '11 at 19:18
  • @AkashKava no. when I try to change the 2.0 .NET project to 4 , it gives more errors . how to overcome that ? and thanks for the help. – Katia Oct 30 '11 at 19:45

4 Answers4

5

var is a reserved keyword. Use a different identifier name or @var.

System.Security.Cryptography.AesCryptoServiceProvider @var;

This may not be the problem - you need to ensure that each project has a reference to System.Core the assembly containing System.Security.Cryptography.

You will also need to ensure that you are targeting a framework version that contains this class (.NET 3.5 and above) - this can be done in the project property pages.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

Check if both projects are referencing System.Core. Probably only the first one has it. You've to add it on both to be able to use AesCryptoServiceProvider.

Moreover, as you can see here AesCryptoServiceProvider is only available since .NET 3.5. Check your project's properties, in particular the Target Framework.

Joao
  • 7,366
  • 4
  • 32
  • 48
  • it's a .net versions issue; the working one is 4 and the none working is 2 . can I add the references without changing the .net version? I did try to change it from 2 to 4 but it gave more errors in reference . and thanks for your help :D . – Katia Oct 30 '11 at 19:33
  • You've to change it to .NET 3.5 or higher otherwise you won't have access to `AesCryptoServiceProvider`. Maybe you're referencing .dlls specific to version 2 and that's why you're getting errors when changing to 4. – Joao Oct 30 '11 at 19:42
  • Change *Target Version* to 4 and remove references that are throwing errors. Add them again if needed using the *Add Reference* wizard. – Joao Oct 30 '11 at 19:43
1

Are the references the same between both project? Just open references and see. I bet you are missing one. However, you really should use a different variable name than var. Also, can you post the exact error?

Jamie
  • 3,094
  • 1
  • 18
  • 28
1

You can't name a variable var because it's a reserved word, use a different name, this will not cause an error :

System.Security.Cryptography.AesCryptoServiceProvider _var;

Edit :

AesCryptoServiceProvider is only supported in .Net framework 4 and 3.5 SP1, change the target framework and it will work and be sure to have System.Security.Cryptography; in that file.

Nasreddine
  • 36,610
  • 17
  • 75
  • 94