[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

How do I resolve this compilation error (non-invocable member cannot be used)?

Asked by Budrophious in Programming for ASP.NET, .NET Framework 2.x, .Net Application Servers

Tags: asp.net, active directory

I am attempting to use C# to access active directory.  I am able to use this same code in VB and it works, but when I try the code in C#, I get the error below at line 136.  I used the vb-to-c# converter at http://www.developerfusion.com/tools/convert/vb-to-csharp/.  

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1955: Non-invocable member 'System.Configuration.ConfigurationManager.AppSettings' cannot be used like a method.

Source Error:
Line 134:            string adPassword = null;
Line 135:        
Line 136:            adUserID = System.Configuration.ConfigurationManager.AppSettings("adUserID").ToString();
Line 137:            adPassword = System.Configuration.ConfigurationManager.AppSettings("adPassword").ToString();
Line 138:        
 
Source File: h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs    Line: 136

Please let me know if you need additional information.  Thank you in advance for your time and assistance!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
-----------------------------------
Detailed Compiler Output:
 
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE> "c:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions.Design\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.Design.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Design\2.0.0.0__b03f5f7f11d50a3a\System.Design.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /out:"C:\Documents and Settings\jkovac2593k\Local Settings\Temp\Temporary ASP.NET Files\scoreboard_active_directory_cs\6f2941ea\e691d0bf\App_Code.np7-w34p.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701 /warnaserror-  "C:\Documents and Settings\jkovac2593k\Local Settings\Temp\Temporary ASP.NET Files\scoreboard_active_directory_cs\6f2941ea\e691d0bf\App_Code.np7-w34p.0.cs" "C:\Documents and Settings\jkovac2593k\Local Settings\Temp\Temporary ASP.NET Files\scoreboard_active_directory_cs\6f2941ea\e691d0bf\App_Code.np7-w34p.1.cs"
 
 
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
 
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(136,66): error CS1955: Non-invocable member 'System.Configuration.ConfigurationManager.AppSettings' cannot be used like a method.
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(137,68): error CS1955: Non-invocable member 'System.Configuration.ConfigurationManager.AppSettings' cannot be used like a method.
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(140,33): error CS0122: 'System.Linq.Strings' is inaccessible due to its protection level
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(140,54): error CS0122: 'System.Linq.Strings' is inaccessible due to its protection level
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(140,75): error CS0122: 'System.Linq.Strings' is inaccessible due to its protection level
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(155,21): error CS0126: An object of a type convertible to 'string' is required
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(160,21): error CS0126: An object of a type convertible to 'string' is required
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(165,49): error CS1061: 'System.DirectoryServices.SearchResultCollection' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.DirectoryServices.SearchResultCollection' could be found (are you missing a using directive or an assembly reference?)
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(169,54): error CS1061: 'System.DirectoryServices.ResultPropertyCollection' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.DirectoryServices.ResultPropertyCollection' could be found (are you missing a using directive or an assembly reference?)
h:\scoreboard_active_directory_cs\App_Code\activeDirectory.cs(171,50): error CS1061: 'System.DirectoryServices.ResultPropertyValueCollection' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.DirectoryServices.ResultPropertyValueCollection' could be found (are you missing a using directive or an assembly reference?)
 
----------------------------------
Complete Compilation Source:
 
Line 1:    using System;
Line 2:    using System.Collections.Generic;
Line 3:    using System.Linq;
Line 4:    using System.Web;
Line 5:    using System.DirectoryServices;
Line 6:    using System.Security.Principal;
Line 7:    
Line 8:    /// <summary>
Line 9:    /// Summary description for activeDirectory
Line 10:   /// </summary>
Line 11:   public class activeDirectory
Line 12:   {
Line 13:       private string m_FirstName;
Line 14:       private string m_LastName;
Line 15:       private string m_Email;
Line 16:       private string m_FullName;
Line 17:       private string m_EmployeeID;
Line 18:       private string m_NTlogin;
Line 19:       private string m_StreetAddress;
Line 20:       private string m_City;
Line 21:       private string m_State;
Line 22:       private string m_ZipCode;
Line 23:       private string m_Department;
Line 24:       private string m_Title;
Line 25:       private string m_Phone;
Line 26:       private string m_Error;
Line 27:       
Line 28:   
Line 29:   	public activeDirectory()
Line 30:   	{
Line 31:   		//
Line 32:   		// TODO: Add constructor logic here
Line 33:   		//
Line 34:   	}
Line 35:   
Line 36:       public string FirstName
Line 37:       {
Line 38:           set { FirstName = m_FirstName; }
Line 39:           get { return FirstName; }  
Line 40:       }
Line 41:       public string LastName
Line 42:       {
Line 43:           set { LastName = m_LastName; }
Line 44:           get { return LastName; }
Line 45:       }
Line 46:   
Line 47:       public string FullName
Line 48:       {  
Line 49:           set { FullName = m_FullName; }
Line 50:           get { return FullName; }
Line 51:       }
Line 52:   
Line 53:       public string EmailAddress
Line 54:       {
Line 55:           set { EmailAddress = m_Email; }
Line 56:           get { return EmailAddress; }
Line 57:       }
Line 58:   
Line 59:       public string NTLogin
Line 60:       {
Line 61:           set { NTLogin = m_NTlogin; }
Line 62:           get { return NTLogin; }
Line 63:       }
Line 64:   
Line 65:       public string EmployeeID
Line 66:       {
Line 67:           set { EmployeeID = m_EmployeeID; }
Line 68:           get { return EmployeeID; }
Line 69:       }
Line 70:   
Line 71:       public string StreetAddress
Line 72:       {
Line 73:           set { StreetAddress = m_StreetAddress; }
Line 74:           get { return StreetAddress; }
Line 75:       }
Line 76:   
Line 77:       public string City
Line 78:       {
Line 79:           set { City = m_City; }
Line 80:           get { return City; }
Line 81:       }
Line 82:   
Line 83:       public string State
Line 84:       {
Line 85:           set { State = m_State; }
Line 86:           get { return State; }
Line 87:       }
Line 88:   
Line 89:       public string ZipCode
Line 90:       {
Line 91:           set { ZipCode = m_ZipCode; }
Line 92:           get { return ZipCode; }
Line 93:       }
Line 94:   
Line 95:       public string Department
Line 96:       {
Line 97:           set { Department = m_Department; }
Line 98:           get { return Department; }
Line 99:       }
Line 100:  
Line 101:      public string Title
Line 102:      {
Line 103:          set { Title = m_Title; }
Line 104:          get { return Title; }
Line 105:      }
Line 106:  
Line 107:      public string Phone
Line 108:      {
Line 109:          set { Phone = m_Phone; }
Line 110:          get { return Phone; }
Line 111:      }
Line 112:      public void GetData(string userid)
Line 113:      {
Line 114:          m_FirstName = GetUserInfo(userid, "GivenName");
Line 115:          m_LastName = GetUserInfo(userid, "sn");
Line 116:          m_FullName = GetUserInfo(userid, "cn");
Line 117:          m_Email = GetUserInfo(userid, "mail");
Line 118:          m_NTlogin = GetUserInfo(userid, "samaccountname");
Line 119:          m_EmployeeID = GetUserInfo(userid, "employeeid");
Line 120:          m_StreetAddress = GetUserInfo(userid, "streetaddress");
Line 121:          m_City = GetUserInfo(userid, "l");
Line 122:          m_State = GetUserInfo(userid, "st");
Line 123:          m_ZipCode = GetUserInfo(userid, "postalcode");
Line 124:          m_Department = GetUserInfo(userid, "department");
Line 125:          m_Title = GetUserInfo(userid, "title");
Line 126:          m_Phone = GetUserInfo(userid, "telephonenumber");
Line 127:      } 
Line 128:  
Line 129:      private string GetUserInfo(string inSAM, string inType) 
Line 130:      { 
Line 131:          try 
Line 132:          { 
Line 133:              string adUserID = null; 
Line 134:              string adPassword = null; 
Line 135:          
Line 136:              adUserID = System.Configuration.ConfigurationManager.AppSettings("adUserID").ToString(); 
Line 137:              adPassword = System.Configuration.ConfigurationManager.AppSettings("adPassword").ToString(); 
Line 138:          
Line 139:              string sPath = "LDAP://DC=myHostName,DC=myDomainName,DC=com"; 
Line 140:              string SamAccount = Strings.Right(inSAM, Strings.Len(inSAM) - Strings.InStr(inSAM, "\\")); 
Line 141:              DirectoryEntry myDirectory = new DirectoryEntry(sPath); 
Line 142:              DirectorySearcher mySearcher = new DirectorySearcher(myDirectory); 
Line 143:              SearchResultCollection mySearchResultColl = default(SearchResultCollection); 
Line 144:              SearchResult mySearchResult = default(SearchResult); 
Line 145:              ResultPropertyCollection myResultPropColl = default(ResultPropertyCollection); 
Line 146:              ResultPropertyValueCollection myResultPropValueColl = default(ResultPropertyValueCollection); 
Line 147:          
Line 148:              mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" + SamAccount + "))"); 
Line 149:              mySearchResultColl = mySearcher.FindAll(); 
Line 150:          
Line 151:              switch (mySearchResultColl.Count) 
Line 152:              { 
Line 153:                  case 0: 
Line 154:                      return "0"; 
Line 155:                      return; 
Line 156:  
Line 157:                      break; 
Line 158:                  case 1: // ERROR: Case labels with binary operators are unsupported : GreaterThan 1: 
Line 159:                      return ">1"; 
Line 160:                      return; 
Line 161:  
Line 162:                      break; 
Line 163:              } 
Line 164:          
Line 165:              mySearchResult = mySearchResultColl.Item(0); 
Line 166:          
Line 167:              myResultPropColl = mySearchResult.Properties; 
Line 168:          
Line 169:              myResultPropValueColl = myResultPropColl.Item(inType); 
Line 170:          
Line 171:              return (string)myResultPropValueColl.Item(0); 
Line 172:          } 
Line 173:          catch (System.Exception ex) 
Line 174:          { 
Line 175:              return ex.Message.ToString(); 
Line 176:          } 
Line 177:      } 
Line 178:  }
[+][-]08/28/09 06:41 AM, ID: 25207523Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, .NET Framework 2.x, .Net Application Servers
Tags: asp.net, active directory
Sign Up Now!
Solution Provided By: TSmooth
Participating Experts: 1
Solution Grade: A
 
[+][-]08/28/09 06:54 AM, ID: 25207654Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/09 07:19 AM, ID: 25207900Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/09 07:30 AM, ID: 25208026Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/09 07:45 AM, ID: 25208194Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625