title: error CS0119: 'ServiceClient' is a type, which is not valid in the given context
body: <p>I am getting  <strong>error CS0119: 'ServiceClient' is a type, which is not valid in the given context</strong> in my project . In my project I have a web reference and in that I'm getting this error . The details are below. Please help guys as I don't understand how to solve this .</p>
  <p><strong>CODE</strong></p>
  <pre><code>    private ServiceClient _client;
      private ServiceClient ProfileServiceClient
      {
          get
          {
              if (_client == null)
              {
                  //Log.Trace(&quot;Initiating Profile client&quot;);
  
                  var watch = Stopwatch.StartNew();
                  ServiceClient _client = new ServiceClient ();
                  watch.Stop();
  
                  Log.Debug(&quot;Initiating Profile took &quot; + watch.ElapsedMilliseconds + &quot; miliseconds&quot;);
              }
              return _client;
           }
        }
  
  
        public AuthenticatedUser ResolveUser(string Id)
      {
          try
          {
              //Log.BusinessTask(string.Format(&quot;Trying to resolve '{0}' via Profile&quot;, vcnId));
              var temp = ServiceClient .getProfileUser(Id, Config.ProfileAppName);
  
              if (temp == null)
              {
                  Log.BusinessTask(string.Format(&quot;No user found in profile with '{0}' as  ID&quot;, Id));
                  var dummyUser = new AuthenticatedUser()
                  {
                      Id = Id,
                      Email = string.Empty,
                      FirstName = Id,
                      LastName = string.Empty
                  };
  
                  dummyUser.Roles.Add(&quot;Viewer&quot;);
  
                  Log.BusinessTask(&quot;Closing Profile client connection&quot;);
                  ServiceClient .Dispose();
  
                  return dummyUser;
              }
  
              Log.BusinessTask(&quot;Profile user found, mapping properties&quot;);
              var result = new AuthenticatedUser
              {
                  Id = temp.userNr,
                  Email = temp.email,
                  FirstName = temp.firstName,
                  LastName = temp.lastName
              };
  
              result.Roles.Add(&quot;Viewer&quot;);
  
              Log.BusinessTask(&quot;Profile user found, mapping roles and applications&quot;);
              var animatrix = ServiceClient .getTheAnimatrix(Id, Config.ProfileAppName, 0, null, null);
  
              if (animatrix != null)
              {
                  foreach (var matrix in animatrix)
                  {
                      if (matrix.authorisations != null)
                      {
                          foreach (var m in matrix.authorisations)
                          {
                              if (m.value.strValue == &quot;Developer Documentation&quot;)
                              {
                                  if (!result.Roles.Any(x =&gt; x.Equals(&quot;Developer&quot;, StringComparison.InvariantCultureIgnoreCase)))
                                      result.Roles.Add(&quot;Developer&quot;);
                              }
  
                              if (m.value.strValue == &quot;IsIt Documentation&quot;)
                              {
                                  if (!result.Roles.Any(x =&gt; x.Equals(&quot;IsIt&quot;, StringComparison.InvariantCultureIgnoreCase)))
                                      result.Roles.Add(&quot;IsIt&quot;);
                              }
  
                              if (m.characteristic == &quot;Managed Application&quot;)
                              {
                                  if (matrix.role.roleName.Contains(&quot;DEVELOPER&quot;))
                                      result.Applications.Add(&quot;Developer&quot; + &quot;/&quot; + m.value.strValue);
                                  else
                                      result.Applications.Add(&quot;IsIt&quot; + &quot;/&quot; + m.value.strValue);
                              }
                          }
                      }
                  }
  
              }
  
              Log.BusinessTask(&quot;Closing Profile client connection&quot;);
              ServiceClient .Dispose();
  
              Log.BusinessTask(&quot;Returning User object&quot;);
              return result;
          }
          catch (Exception e)
          {
              Log.Error(string.Format(&quot;Couldn't reach the PROFILE auth webservice : {0}&quot;, e));
          }
  
          return new AuthenticatedUser { FirstName = &quot;Viewer&quot;, Id = &quot;none&quot; };
      }
  </code></pre>
  <p><strong>In Referrence.cs file</strong></p>
  <pre><code>         public ServiceClient () {
            this.Url = 
            global::ProxyComponent.Properties.Settings.Default.ProxyComponent_Services_ServiceClient _ServiceClient ;
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
              this.UseDefaultCredentials = true;
              this.useDefaultCredentialsSetExplicitly = false;
            }
             else {
              this.useDefaultCredentialsSetExplicitly = true;
            }
          }
  </code></pre>
  <p>I am getting error in this particular line <strong>ServiceClient _client = new ServiceClient ();</strong> . Any solution for this error or any clue ? In method AuthenticatedUser ResolveUser(string Id) line var temp = ServiceClient .getProfileUser(Id, Config.ProfileAppName) ServiceClient throws error like threw an exception of type 'System.TypeInitializationException' .
  <strong>InnerException    {&quot;Object reference not set to an instance of an object.&quot;}</strong></p>
  <p><strong>SOLUTION</strong>
  Okay I found my solution . I have to change this line</p>
  <pre><code>   var temp = ServiceClient .getProfileUser(Id, Config.ProfileAppName);
  </code></pre>
  <p>to this</p>
  <pre><code>     _client = new ServiceClient();
       var temp = _client.getProfileUser(Id, Config.ProfileAppName);
  </code></pre>