Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting System.ArgumentNullException: Value cannot be null. (Parameter 'key') error #119

Open
CMYaron opened this issue Apr 2, 2025 · 4 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers needs-review

Comments

@CMYaron
Copy link

CMYaron commented Apr 2, 2025

when running the sample, after adding the key to codspace i am getting this error when i run dont run:
/workspaces/Generative-AI-for-test/02-SetupDevEnvironment/src/BasicChat-01MEAI/Program.cs(11,35): warning CS8604: Possible null reference argument for parameter 'key' in 'ApiKeyCredential.ApiKeyCredential(string key)'.
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.ClientModel.Internal.Argument.AssertNotNullOrEmpty(String value, String name)
at System.ClientModel.ApiKeyCredential.Update(String key)
at System.ClientModel.ApiKeyCredential..ctor(String key)
at Program.

$(String[] args) in /workspaces/Generative-AI-for-test/02-SetupDevEnvironment/src/BasicChat-01MEAI/Program.cs:line 11

i have the right key in the Codespaces secrets

Copy link

github-actions bot commented Apr 2, 2025

👋 Thanks for contributing @CMYaron! We will review the issue and get back to you soon.

@elbruno elbruno added bug Something isn't working good first issue Good for newcomers labels Apr 3, 2025
@elbruno
Copy link
Collaborator

elbruno commented Apr 3, 2025

Hi @CMYaron

I reproduced your error by setting an empty string for the Environment.GetEnvironmentVariable("GITHUB_TOKEN") value. Therefore there should be an error with your token.

Image

2 options:

  1. Please check the creation of your GH token (https://github.com/microsoft/Generative-AI-for-beginners-dotnet/tree/main/02-SetupDevEnvironment#creating-a-personal-access-token-for-github-model-access)
  2. Check this code sample, where you can uncomment and show the value of the token before using it, so you can see if the key is correct (https://gist.github.com/elbruno/8593452caa9dabf45aad8bf6d1db3281)

Best!

@CMYaron
Copy link
Author

CMYaron commented Apr 3, 2025 via email

@elbruno
Copy link
Collaborator

elbruno commented Apr 4, 2025

I am taking the value from codespace secrets
Its according to details in the example
When putting the key hardcode its working but this is not the case …

Get Outlook for iOShttps://aka.ms/o0ukef

Can you check this line ?

Console.WriteLine($"GITHUB_TOKEN: {Environment.GetEnvironmentVariable("GITHUB_TOKEN")}");

And check, maybe you need to manually store the GitHub_Token. Examples below:

If you're using bash:

export GITHUB_TOKEN="<your-github-token-goes-here>"

If you're in powershell:

$Env:GITHUB_TOKEN="<your-github-token-goes-here>"

If you're using Windows command prompt:

set GITHUB_TOKEN=<your-github-token-goes-here>

Please, try to run this and later the sample code.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers needs-review
Projects
None yet
Development

No branches or pull requests

2 participants