We help IT Professionals succeed at work.
Get Started

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

9,956 Views
Last Modified: 2013-11-07
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!

-----------------------------------
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:  }

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE