{"action":"opened","issue":{"url":"https://api.github.com/repos/Azure/azure-sdk-for-net/issues/3361","repository_url":"https://api.github.com/repos/Azure/azure-sdk-for-net","labels_url":"https://api.github.com/repos/Azure/azure-sdk-for-net/issues/3361/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-sdk-for-net/issues/3361/comments","events_url":"https://api.github.com/repos/Azure/azure-sdk-for-net/issues/3361/events","html_url":"https://github.com/Azure/azure-sdk-for-net/issues/3361","id":235394511,"number":3361,"title":"Fluent: WithExistingNetworkSecurityGroup not working for newly created NSG?","user":{"login":"TimLovellSmith","id":2711795,"avatar_url":"https://avatars3.githubusercontent.com/u/2711795?v=3","gravatar_id":"","url":"https://api.github.com/users/TimLovellSmith","html_url":"https://github.com/TimLovellSmith","followers_url":"https://api.github.com/users/TimLovellSmith/followers","following_url":"https://api.github.com/users/TimLovellSmith/following{/other_user}","gists_url":"https://api.github.com/users/TimLovellSmith/gists{/gist_id}","starred_url":"https://api.github.com/users/TimLovellSmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimLovellSmith/subscriptions","organizations_url":"https://api.github.com/users/TimLovellSmith/orgs","repos_url":"https://api.github.com/users/TimLovellSmith/repos","events_url":"https://api.github.com/users/TimLovellSmith/events{/privacy}","received_events_url":"https://api.github.com/users/TimLovellSmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-12T23:30:00Z","updated_at":"2017-06-12T23:30:00Z","closed_at":null,"body":"I recently upgraded to 1.0.0. I had some code which I reworked since the previous version which ended up after the upgrade looking like\r\n\r\n````\r\ntry {\r\n    logger.Info($\"Begin create NSG {nsgName} in {resourceGroup.Id}...\");\r\n                nsg = await azureSub.NetworkSecurityGroups.Define(nsgName)\r\n                .WithRegion(resourceGroup.Region)\r\n                .WithExistingResourceGroup(resourceGroup)\r\n                .WithTag(\"foo\", OwnerName)\r\n                .DefineRule(\"allowAllInbound\").AllowInbound().FromAnyAddress().FromAnyPort().ToAnyAddress().ToAnyPort().WithAnyProtocol().WithPriority(100).Attach()\r\n                .DefineRule(\"allowAllOutbound\").AllowOutbound().FromAnyAddress().FromAnyPort().ToAnyAddress().ToAnyPort().WithAnyProtocol().WithPriority(101).Attach()\r\n                .CreateAsync();\r\n                logger.Info($\"Successfully created NSG: {nsg.Name}.\");\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                LogTheExceptionDetails(e, logger);\r\n                throw;\r\n            }\r\n\r\n            NSGId = nsg.Id;\r\n\r\n            // Create a VNET + subnet in the resource group\r\n            try\r\n            {\r\n                logger.Info($\"Begin create ARM VNET {Name} in {resourceGroup.Id} referencing NSG {NSGId}...\");\r\n                vnet = await azureSub.Networks.Define(Name)\r\n                    .WithRegion(resourceGroup.Region)\r\n                    .WithExistingResourceGroup(resourceGroup)\r\n                    .WithTag(\"foo\", OwnerName)\r\n                    .WithAddressSpace(\"172.16.0.0/12\")\r\n                    .DefineSubnet(\"subnet\").WithAddressPrefix(\"172.16.0.0/16\").WithExistingNetworkSecurityGroup(nsg).Attach()\r\n                    .CreateAsync();\r\n                logger.Info($\"Successfully created VNET: {vnet.Name}.\");\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                LogTheExceptionDetails(e, logger);\r\n                throw;\r\n            }\r\n```\r\n\r\nBut it seems to have been failing due to the WithExistingNetworkSecurityGroup not working somehow in this scenario - here is the server response!\r\n\r\n```\r\n[Deployment: iaas202c3, Id: 277] More failure details: Response?.StatusCode=BadRequest, Content={\r\n  \"error\": {\r\n    \"code\": \"InvalidRequestFormat\",\r\n    \"message\": \"Cannot parse the request.\",\r\n    \"details\": [\r\n      {\r\n        \"code\": \"MissingJsonReferenceId\",\r\n        \"message\": \"Value for reference id is missing. Path properties.subnets[0].properties.networkSecurityGroup.\"\r\n      }\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\nI don't really see why this code could fail though unless its a bug - or unless I'm not testing the code that I think I am - nsg should be initialized right, so WithExistingNetworkSecurityGroup should work right? (in the logs I also see `[Deployment: iaas202c3, Id: 277] Successfully created NSG: weur299254vnetnsg.` ...)"}}
{"actor":{"display_login":"TimLovellSmith"}}