{"action":"opened","issue":{"url":"https://api.github.com/repos/Azure/autorest/issues/930","repository_url":"https://api.github.com/repos/Azure/autorest","labels_url":"https://api.github.com/repos/Azure/autorest/issues/930/labels{/name}","comments_url":"https://api.github.com/repos/Azure/autorest/issues/930/comments","events_url":"https://api.github.com/repos/Azure/autorest/issues/930/events","html_url":"https://github.com/Azure/autorest/issues/930","id":146846197,"number":930,"title":"Make Credentials optional","user":{"login":"henning-krause","id":12197701,"avatar_url":"https://avatars.githubusercontent.com/u/12197701?v=3","gravatar_id":"","url":"https://api.github.com/users/henning-krause","html_url":"https://github.com/henning-krause","followers_url":"https://api.github.com/users/henning-krause/followers","following_url":"https://api.github.com/users/henning-krause/following{/other_user}","gists_url":"https://api.github.com/users/henning-krause/gists{/gist_id}","starred_url":"https://api.github.com/users/henning-krause/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henning-krause/subscriptions","organizations_url":"https://api.github.com/users/henning-krause/orgs","repos_url":"https://api.github.com/users/henning-krause/repos","events_url":"https://api.github.com/users/henning-krause/events{/privacy}","received_events_url":"https://api.github.com/users/henning-krause/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-08T07:48:56Z","updated_at":"2016-04-08T07:48:56Z","closed_at":null,"body":"I generated a C# client for my REST service. This service has some operations requiring authentication, but others do not. So I've created my client with the -AddCredential parameter.\r\n\r\nBut now, I can't create a service instance without credentials. \r\n\r\nLooking at the constructor, the code is rather odd:\r\n\r\n```\r\nif (credentials == null)\r\n{\r\n    throw new ArgumentNullException(\"credentials\");\r\n}\r\nthis.Credentials = credentials;\r\nif (this.Credentials != null)\r\n{\r\n    this.Credentials.InitializeServiceClient(this);\r\n}\r\n```\r\n\r\nNow, the latter part of the constructor makes the credential parameter look like it's optional. But the null check in the first lines prevent this.\r\n\r\nNow, I've worked around this issue by creating a custom ServiceCredential class, which simply does nothing:\r\n\r\n```\r\nprivate class AnonymousCredential : ServiceClientCredentials\r\n{\r\n\tpublic static ServiceClientCredentials Instance { get; } = new AnonymousCredential();\r\n\r\n\tprivate AnonymousCredential()\r\n\t{\r\n\t}\r\n}\r\n```\r\n\r\nBut this is rather inconvenient. Could the null check be removed from the generated constructor?"}}