Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2031
  • Last Modified:

Cannot convert from 'string' to 'System.Collections.Generic.List<string>'

I can't figure out why it's complaining  I must be passing the generic list wrong or something

I have in my class this:

        static void Main(string[] args)
        {
            List<string> rightToCheck = null;
            rightToCheck.Add("Delete");

            UAuthorizationProvider provider = new UAuthorizationProvider();
            IPrincipal principal;

            provider.Authorize(principal, rightToCheck);
        }

cannot convert from 'string' to 'System.Collections.Generic.List<string>'

My Authorize method is declared like this:

        public bool Authorize(IPrincipal principal, List<string> rightsRequested)
        {
             ...
         }
0
dba123
Asked:
dba123
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
on which line does the error occur?
0
 
Jai STech ArchCommented:
try using the full qualifier...
System.Collections.Generic.List<string> rightToCheck = null;

public bool Authorize(IPrincipal principal, System.Collections.Generic.List<string>  rightsRequested)
0
 
dba123Author Commented:
provider.Authorize(principal, rightToCheck);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dba123Author Commented:
Ok, I actually set it to a value now but still same error:

            IPrincipal principal = new GenericPrincipal(new GenericIdentity("John"), new string[] { "Manager" });
0
 
dba123Author Commented:
wait, I think it is working now.  Duh.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>new string[] { "Manager" }
is NOT the same as Generic.List<string>
so your last try cannot work...


looking...
0
 
dba123Author Commented:
no, that's for the principal.  I'm expecting a principal which I gave it.  The generic list is for the second argument.  I'm talking about the first.
0
 
dba123Author Commented:
so in other words I just tried this with no luck still

    class VAuthorizationProviderTesting
    {
        static void Main(string[] args)
        {
            List<string> rightToCheck = null;
            rightToCheck.Add("Delete");

            VAuthorizationProvider provider = new VAuthorizationProvider();
            IPrincipal principal = new GenericPrincipal(new GenericIdentity("Don"), new string[] { "Manager" });

            provider.Authorize(principal, rightToCheck);
        }
    }
}
0
 
KelmenCommented:
Shouldn't you need to initialize the var 1st?

            List<string> rightToCheck = new List<string>();
            rightToCheck.Add("Delete");
0
 
SU-30MKICommented:
Kelmen is right. first initialize it
List<string> rightToCheck =new List<string>();
then you can add.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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