• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

'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           }
0
dba123
Asked:
dba123
2 Solutions
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now