Click here to Skip to main content
16,022,901 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to convert my VB.NET property to C# for my AD authentication. I keep getting errors but this is the VB.NET code.

VB.NET
Public ReadOnly Property CN() As String
        Get
            Return CType(_adUser.Item("cn").Value, String)
        End Get
    End Property


I converted it to this in C#
C#
public string CN
        {
            get {return (string)_adUser.Item["cn"];}
        }

but it throws an error..any ideas?

In answer to your question.
public ADUser _adUser;
_adUser is a class.
Posted
Updated 19-Mar-10 6:15am
v3

CType does more then a static cast; you'd want something more like:

public string CN
{
get
{
return _adUser.Item["cn"].Value.ToString();
}
}
 
Share this answer
 
What is _adUser ? Is "cn" a valid index? If so, try changing the line:

get {return (string)_adUser.Item["cn"];}


to

get {return _adUser.Item["cn"].ToString();}
 
Share this answer
 
Late post sorry. turns out it was something in my webconfig. DOH!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900