title: C#:ArgumentNullException: String reference not set to an instance of a String. Parameter name: s System.Text.Encoding.GetBytes(string s)
body: <p>I have this method to generate a jwt token using c# .netcore 3.1 version.</p>
  <pre><code>      [HttpPost]
          public async Task&lt;IActionResult&gt; CreateToken([FromBody] LoginViewModel model)
          {
              if( ModelState.IsValid)
              {
                  var user = await _userManager.FindByNameAsync(model.Username);
  
                  if (user != null)
                  {
                      var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false); 
  
                      if (result.Succeeded)
                      {
                          // Create the token
                          var claims = new[]
                          {
                              new Claim(JwtRegisteredClaimNames.Sub, user.Email),
                              new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                              new Claim(JwtRegisteredClaimNames.UniqueName, user.UserName),
                          };
  
                          var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config[&quot;Tokens:Key&quot;]));
                          var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  
                          var token = new JwtSecurityToken(
                              _config[&quot;Tokens:Issuer&quot;], 
                              _config[&quot;Tokens:Audience&quot;], 
                              claims,
                              signingCredentials: creds,
                              expires: DateTime.UtcNow.AddMinutes(30));
  
                          var results = new
                          {
                              token = new JwtSecurityTokenHandler().WriteToken(token),
                              expiration = token.ValidTo
                          };
                          return Created(&quot;&quot;, results);
                          
                      }
                  }
              }
  
              return BadRequest();
          }
      }
  </code></pre>
  <p>When I call the CreateToken method API via postman :</p>
  <pre><code>    When I call this API via postman :
      http://localhost:8888/account/CreateToken
  </code></pre>
  <p>I'm getting this error</p>
  <pre><code>    
      System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's')
     at System.Text.Encoding.GetBytes(String s)
     at DutchTreat.Contollers.AccountController.CreateToken(LoginViewModel model) in E:\.NET Core and Angular\DutchTreat\Contollers\AccountController.cs:line 101
  </code></pre>
  <p>After some debugging I was able to find the error is coming Because of this line</p>
  <pre><code> var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config[&quot;Tokens:Key&quot;]));
  </code></pre>
  <p>This is my config file I Use</p>
  <pre><code>{
    &quot;Color&quot;: {
      &quot;Favourite&quot;: &quot;Blue&quot;
    },
    &quot;ConnectionStrings&quot;: {
      &quot;DutchContextDb&quot;: &quot;Data Source=(localdb)\\ProjectsV13;Initial Catalog=DutchTreatDb;Integrated Security=True;Connect Timeout=30;MultipleActiveResultSets=true&quot;
    },
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;DutchTreat&quot;: &quot;Information&quot;,
        &quot;Microsoft&quot;: &quot;Warning&quot;
      },
      &quot;Tokens&quot;: {
        &quot;Key&quot;: &quot;a;sdlkfja; lsdkfj ;alksdfj ;alksdfj; aiefj;lskij;flds&quot;,
        &quot;Issuer&quot;: &quot;http://localhost:8888&quot;,
        &quot;Audience&quot;: &quot;http://localhost:8888&quot;
      }
    }
  }
  </code></pre>
  <p>Kindly help to fix this error</p>