'System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<string>>.ContainsValue(System.Collections.Generic.List<string>)' has invalid arguments

I can't see what I"m doing wrong here when I try passing the generic string to the ContainsValue method:

1            public bool Authorize(IPrincipal principal, List<string> rightsRequested)
2            {
3                bool result = false;
4    
5                if (principal == null) throw new System.ArgumentNullException("IPrincipal is null");
6                if (rightsRequested.Count < 1) throw new System.ArgumentNullException("rightsRequested generic string is null");
7    
8                if ((rightsRequested.Count == 1) && (dicRights.ContainsKey(principal.Identity.Name)))
9                    result = dicRights.ContainsValue(rightsRequested[0]);
10              
11               return result;
12           }
LVL 1
dba123Asked:
Who is Participating?
 
REA_ANDREWCommented:
This accepted solution here may help

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=142896&SiteID=1

Andrew
0
 
dstanley9Commented:
You've got several questions on this that I've seen, so I'll try and outline the issue:

1) dicRights is a key-value dictionary where the key is a string and the value is a List<string>
2) dicRights.ContainsKey(key) will return true if the key value is found
3) dicRights[key] will return the LIST of strings, so to do it in one call you'll need to do

result = dicRights[key].Contains(rightsRequested[0]);
0
 
JimBrandleyCommented:
dstanley9 is correct, but if you search for a key that is not in the dictionary, this will throw a null reference exception. The following wiil not:

bool result = false;
List<string> current = dicRights[principal.Identity.Name];
if (current != null)
   result = current.Contains(rightsRequested[0]);

Jim
0
 
dba123Author Commented:
I found out that it was trying to compare two reference types, not 2 strings which is why it wasn't matching the string when looking up.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.