Can't find `DataProtectionScope` and `ProtectedData` classes in System.Security.Cryptography
Asked Answered
V

7

18

I've referred the file System.Security.dll as described in this article but according to my IDE, the line using System.Security.Cryptography; can be safely removed as it's not being used.

The same IDE tells me that I've got an error with DataProtectionScope and ProtectedData. Those are supposed to be in that namespace. However, when I dot my way through the packages, I can't see them in there.

Is the article wrong? How can I access the two classes?

Varied answered 21/9, 2012 at 7:40 Comment(8)
That should work. What version of .NET Framework are you using? For which platform? How to you make the reference? PS: what's DataProtextScope?Spatola
How are we supposed to reproduce this without your code?Candlewood
@Candlewood What code? I'm typing in System.Security.Cryptography. and in the list I'm getting, there's no DataProtectionScope or ProtectedData. SO, I guess the code is: System.Security.Cryptography. but that's hardly a new information.Varied
@SimonMourier VS10, .NET4. I added the reference the usual way, by right-clicking on references in the pane to the right and pointed to the assembly in question. DataProtextScope is a typo - see the correction in the subject. :)Varied
That should definitely work if you see the System.Security assembly listed under the project's References folder.Spatola
So what does appear in the list when you type in System.Security.Cryptography.? I ask because I tried this on my machine and could see both DataProtectionScope and ProtectedData.Cheboksary
It works fine. My guess? A code 18. Soo... I doubt anyone could find what's wrong without getting his hands in your solution.Wondering
These days you can get this assembly from NuGet: nuget.org/packages/System.Security.Cryptography.ProtectedDataIvon
M
-9

This might be a slap in your face because you've probably tried that (and you haven't, you might deserve one). What happens if you reinstall the whole IDE? And I meant really the whole thing. Remove the framwork, the VS, remove the files, go paranoid and clean up the trash can, switch to a different installation directory etc. Does the problem still remains?

I know it doesn't explain why it happened but at this stage I'm guessing you're mostly interested in how to kill the problem.

If you have access to a spare computer - why don't you install VS on that machine and see if you can reproduce the error. If not, then there's something fishy with your primary machine and you'll probably never know what happened.

I'm stressing here that it's only a list of general suggestions that every programmer should rely on when nothing sane nor logical seems to work. And yes, I do hate computers. I love programming but I hate computers. They are like small, evil people with keyboards...

Manno answered 3/11, 2012 at 0:47 Comment(3)
I really, truly don't want to reinstall those things. However, I even trulier don't want to develop data encryptors myself... I'll give it a whack, starting with the least inconvenient one...Varied
This is very frustrating - the problem is gone but I have no idea why... Or how it came up. What do you guys think?Varied
The problem is gone because you eliminated the cause of the problem. I'm guessing you'd like to know what that cause was. You're probably not going to know, ever. Especially if you can't reproduce the behavior. I'm glad the issue is resolved, at least. Also, I think the other replies came much sooner and perhaps one of them deserves the +50 more than I. You might consider switching the bounty to someone else. :)Manno
D
76

As @Coral Doe mentioned in a comment under @Dave Lucre:

"Had a similar problem and this worked. using System.Security.Cryptography; didn't [show] me [ProtectedData] and ProtectedMemory until I had referenced the System.Security.dll for the specific framework."

This fixed the issue for me. Specifically, I performed these steps:

  1. Open the project in Visual Studio.
  2. Right-click the project's name in Solution Explorer then choose Properties.
  3. Click the References tab on the left.
  4. Click the Add button.
  5. Click the .NET tab.
  6. Select System.Security and click OK to add the reference.

Hope this helps.

Dink answered 16/8, 2013 at 21:7 Comment(5)
This should be the answer. I keep forgetting to do this.Mccully
upvote for not having me reinstall the entire visual studioFeaturelength
@George Brian, same thing happened to me (#46206437). these two are part of a voting ring probably.Mongrel
Works for me in .NET 4.6.2 but not in .NET Core.Driftwood
This alone didn't help me with VS 2019. In addition I had to go Project>Add Reference>Assemblies and check System.Security.Kook
W
9

I have referenced the System.Security.dll here: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Security.dll

Added using System.Security.Cryptography; and I can see both DataProtectionScope and ProtectedData.

I'm targeting the .net 4.0 full framework (not client profile).

What framework are you targeting?

Wallie answered 30/10, 2012 at 22:38 Comment(1)
Had a similar problem and this worked. using System.Security.Cryptography; didn't showed me ProtectdData and ProtectedMemory until I had referenced the System.Security.dll for the specific framework.Wallaby
S
6

I had to add this NuGet package in addition to System.Security.Cryptography.

It is https://www.nuget.org/packages/System.Security.Cryptography.ProtectedData/.

After that, System.Security.Cryptography became "used".

Steinbach answered 5/3, 2019 at 14:56 Comment(1)
For me it was: System.Security.Cryptography.ProtectedDataGudrunguelderrose
H
1

As @Dave Lucre asked, what framework is your application targeting? Visual Studio creates all new applications to use the Client Profile by default (which is asinine in my opinion), and it causes all sorts of trouble if you don't specifically change it back. Give that a look, then see where we go from there.

Hedve answered 2/11, 2012 at 14:24 Comment(1)
I agree that the choice of the primary target platform to Client Profile is borderline insane. I've checked that as well. I don't have those classes anywhere.Varied
H
0

Remove references System.Security.Cryptography and add it again.

It works in my case.

Horseman answered 13/10, 2020 at 12:7 Comment(0)
S
0

I'm sorry, I know that this is a quite old post, but I'm having this issue now and the only workaround that I've found is:

  1. Follow the steps mentioned in George Brian's answer
  2. Use System.Security.Cryptography.DataProtectionScope scope = System.Security.Cryptography.DataProtectionScope.LocalMachine; instead of DataProtectionScope scope = DataProtectionScope.LocalMachine;
Settles answered 15/1, 2021 at 17:1 Comment(0)
M
-9

This might be a slap in your face because you've probably tried that (and you haven't, you might deserve one). What happens if you reinstall the whole IDE? And I meant really the whole thing. Remove the framwork, the VS, remove the files, go paranoid and clean up the trash can, switch to a different installation directory etc. Does the problem still remains?

I know it doesn't explain why it happened but at this stage I'm guessing you're mostly interested in how to kill the problem.

If you have access to a spare computer - why don't you install VS on that machine and see if you can reproduce the error. If not, then there's something fishy with your primary machine and you'll probably never know what happened.

I'm stressing here that it's only a list of general suggestions that every programmer should rely on when nothing sane nor logical seems to work. And yes, I do hate computers. I love programming but I hate computers. They are like small, evil people with keyboards...

Manno answered 3/11, 2012 at 0:47 Comment(3)
I really, truly don't want to reinstall those things. However, I even trulier don't want to develop data encryptors myself... I'll give it a whack, starting with the least inconvenient one...Varied
This is very frustrating - the problem is gone but I have no idea why... Or how it came up. What do you guys think?Varied
The problem is gone because you eliminated the cause of the problem. I'm guessing you'd like to know what that cause was. You're probably not going to know, ever. Especially if you can't reproduce the behavior. I'm glad the issue is resolved, at least. Also, I think the other replies came much sooner and perhaps one of them deserves the +50 more than I. You might consider switching the bounty to someone else. :)Manno

© 2022 - 2024 — McMap. All rights reserved.