{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/31590899","id":31590899,"diff_hunk":"@@ -45,25 +41,43 @@ private AbstractCodeType ParentType\n \n         private ImmutableArray<EnvDTE.CodeElement> GetParts()\n         {\n-            var partsBuilder = ImmutableArray.CreateBuilder<EnvDTE.CodeElement>();\n-            var symbol = ParentType.LookupSymbol();\n-\n-            foreach (var location in symbol.Locations.Where(l => l.IsInSource))\n+            // Retrieving the parts is potentially very expensive because it can force multiple FileCodeModels to be instantiated.\n+            // Here, we cache the result to avoid having to perform these calculations each time GetParts() is called.\n+            // This *could* be an issue because it means that a PartialTypeCollection will not necessarily reflect the\n+            // current state of the user's code. However, because a new PartialTypeCollection is created everytime a the Parts\n+            // property is accessed on CodeClass, CodeStruct or CodeInterface, consumers would hit this behavior rarely.\n+            if (this._parts == null)\n             {\n-                var tree = location.SourceTree;\n-                var document = this.Workspace.CurrentSolution.GetDocument(tree);\n+                var partsBuilder = ImmutableArray.CreateBuilder<EnvDTE.CodeElement>();\n \n-                var fileCodeModelObject = this.Workspace.GetFileCodeModel(document.Id);\n-                var fileCodeModel = ComAggregate.GetManagedObject<FileCodeModel>(fileCodeModelObject);\n+                var solution = this.Workspace.CurrentSolution;\n+                var symbol = ParentType.LookupSymbol();\n \n-                var element = fileCodeModel.CodeElementFromPosition(location.SourceSpan.Start, ParentType.Kind);\n-                if (element != null)\n+                foreach (var location in symbol.Locations.Where(l => l.IsInSource))\n                 {\n-                    partsBuilder.Add(element);\n+                    var tree = location.SourceTree;\n+                    var document = solution.GetDocument(tree);\n+\n+                    if (document != null)\n+                    {\n+                        var fileCodeModelObject = this.Workspace.GetFileCodeModel(document.Id);\n+                        if (fileCodeModelObject != null)","path":"src/VisualStudio/Core/Impl/CodeModel/Collections/PartialTypeCollection.cs","position":55,"original_position":55,"commit_id":"2edf59683f243be6bb65da60aaa985762f959455","original_commit_id":"2edf59683f243be6bb65da60aaa985762f959455","user":{"login":"Pilchie","id":312835,"avatar_url":"https://avatars.githubusercontent.com/u/312835?v=3","gravatar_id":"","url":"https://api.github.com/users/Pilchie","html_url":"https://github.com/Pilchie","followers_url":"https://api.github.com/users/Pilchie/followers","following_url":"https://api.github.com/users/Pilchie/following{/other_user}","gists_url":"https://api.github.com/users/Pilchie/gists{/gist_id}","starred_url":"https://api.github.com/users/Pilchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pilchie/subscriptions","organizations_url":"https://api.github.com/users/Pilchie/orgs","repos_url":"https://api.github.com/users/Pilchie/repos","events_url":"https://api.github.com/users/Pilchie/events{/privacy}","received_events_url":"https://api.github.com/users/Pilchie/received_events","type":"User","site_admin":false},"body":"Since this is believed to be impossible, add a comment stating why the null check exists?","created_at":"2015-06-03T03:07:45Z","updated_at":"2015-06-03T03:07:45Z","html_url":"https://github.com/dotnet/roslyn/pull/3267#discussion_r31590899","pull_request_url":"https://api.github.com/repos/dotnet/roslyn/pulls/3267","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/31590899"},"html":{"href":"https://github.com/dotnet/roslyn/pull/3267#discussion_r31590899"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/3267"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/3267","id":36778226,"html_url":"https://github.com/dotnet/roslyn/pull/3267","diff_url":"https://github.com/dotnet/roslyn/pull/3267.diff","patch_url":"https://github.com/dotnet/roslyn/pull/3267.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/3267","number":3267,"state":"open","locked":false,"title":"Code Model: Clean up PartialTypeCollection, making it more resilient","user":{"login":"DustinCampbell","id":116161,"avatar_url":"https://avatars.githubusercontent.com/u/116161?v=3","gravatar_id":"","url":"https://api.github.com/users/DustinCampbell","html_url":"https://github.com/DustinCampbell","followers_url":"https://api.github.com/users/DustinCampbell/followers","following_url":"https://api.github.com/users/DustinCampbell/following{/other_user}","gists_url":"https://api.github.com/users/DustinCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/DustinCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DustinCampbell/subscriptions","organizations_url":"https://api.github.com/users/DustinCampbell/orgs","repos_url":"https://api.github.com/users/DustinCampbell/repos","events_url":"https://api.github.com/users/DustinCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/DustinCampbell/received_events","type":"User","site_admin":false},"body":"A crash with no reliable repro was reported for Silverlight projects with a call stack pointing to Code Model's PartialTypeCollection.GetParts(). While it wasn't possible to figure out a repro from the call stack, it was clear that a NullReferenceException was being thrown after ```VisualStudioWorkspace.GetFileCodeModel(DocumentId)``` returned null. This change makes that code more resilient against crashes. Additionally, it caches the result of GetParts().","created_at":"2015-06-02T21:50:02Z","updated_at":"2015-06-03T03:07:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f1bba25a38136b54e118c5724aaa4d8a6a394cb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn/pulls/3267/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn/pulls/3267/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/3267/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/2edf59683f243be6bb65da60aaa985762f959455","head":{"label":"DustinCampbell:fix-codemodel-partialtypecollection","ref":"fix-codemodel-partialtypecollection","sha":"2edf59683f243be6bb65da60aaa985762f959455","user":{"login":"DustinCampbell","id":116161,"avatar_url":"https://avatars.githubusercontent.com/u/116161?v=3","gravatar_id":"","url":"https://api.github.com/users/DustinCampbell","html_url":"https://github.com/DustinCampbell","followers_url":"https://api.github.com/users/DustinCampbell/followers","following_url":"https://api.github.com/users/DustinCampbell/following{/other_user}","gists_url":"https://api.github.com/users/DustinCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/DustinCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DustinCampbell/subscriptions","organizations_url":"https://api.github.com/users/DustinCampbell/orgs","repos_url":"https://api.github.com/users/DustinCampbell/repos","events_url":"https://api.github.com/users/DustinCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/DustinCampbell/received_events","type":"User","site_admin":false},"repo":{"id":30651839,"name":"roslyn","full_name":"DustinCampbell/roslyn","owner":{"login":"DustinCampbell","id":116161,"avatar_url":"https://avatars.githubusercontent.com/u/116161?v=3","gravatar_id":"","url":"https://api.github.com/users/DustinCampbell","html_url":"https://github.com/DustinCampbell","followers_url":"https://api.github.com/users/DustinCampbell/followers","following_url":"https://api.github.com/users/DustinCampbell/following{/other_user}","gists_url":"https://api.github.com/users/DustinCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/DustinCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DustinCampbell/subscriptions","organizations_url":"https://api.github.com/users/DustinCampbell/orgs","repos_url":"https://api.github.com/users/DustinCampbell/repos","events_url":"https://api.github.com/users/DustinCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/DustinCampbell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DustinCampbell/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":true,"url":"https://api.github.com/repos/DustinCampbell/roslyn","forks_url":"https://api.github.com/repos/DustinCampbell/roslyn/forks","keys_url":"https://api.github.com/repos/DustinCampbell/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DustinCampbell/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DustinCampbell/roslyn/teams","hooks_url":"https://api.github.com/repos/DustinCampbell/roslyn/hooks","issue_events_url":"https://api.github.com/repos/DustinCampbell/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/DustinCampbell/roslyn/events","assignees_url":"https://api.github.com/repos/DustinCampbell/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/DustinCampbell/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/DustinCampbell/roslyn/tags","blobs_url":"https://api.github.com/repos/DustinCampbell/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DustinCampbell/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DustinCampbell/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/DustinCampbell/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DustinCampbell/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/DustinCampbell/roslyn/languages","stargazers_url":"https://api.github.com/repos/DustinCampbell/roslyn/stargazers","contributors_url":"https://api.github.com/repos/DustinCampbell/roslyn/contributors","subscribers_url":"https://api.github.com/repos/DustinCampbell/roslyn/subscribers","subscription_url":"https://api.github.com/repos/DustinCampbell/roslyn/subscription","commits_url":"https://api.github.com/repos/DustinCampbell/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/DustinCampbell/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/DustinCampbell/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/DustinCampbell/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/DustinCampbell/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/DustinCampbell/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DustinCampbell/roslyn/merges","archive_url":"https://api.github.com/repos/DustinCampbell/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DustinCampbell/roslyn/downloads","issues_url":"https://api.github.com/repos/DustinCampbell/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/DustinCampbell/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/DustinCampbell/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/DustinCampbell/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DustinCampbell/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/DustinCampbell/roslyn/releases{/id}","created_at":"2015-02-11T14:36:20Z","updated_at":"2015-04-22T18:16:20Z","pushed_at":"2015-06-02T21:18:32Z","git_url":"git://github.com/DustinCampbell/roslyn.git","ssh_url":"git@github.com:DustinCampbell/roslyn.git","clone_url":"https://github.com/DustinCampbell/roslyn.git","svn_url":"https://github.com/DustinCampbell/roslyn","homepage":"","size":81949,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"c8991a08d5b6d63af5399e5dae270c544d7f69bf","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":29078997,"name":"roslyn","full_name":"dotnet/roslyn","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn","forks_url":"https://api.github.com/repos/dotnet/roslyn/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn/releases{/id}","created_at":"2015-01-11T02:39:03Z","updated_at":"2015-06-03T00:49:54Z","pushed_at":"2015-06-03T01:49:40Z","git_url":"git://github.com/dotnet/roslyn.git","ssh_url":"git@github.com:dotnet/roslyn.git","clone_url":"https://github.com/dotnet/roslyn.git","svn_url":"https://github.com/dotnet/roslyn","homepage":"","size":148934,"stargazers_count":2427,"watchers_count":2427,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":519,"mirror_url":null,"open_issues_count":904,"forks":519,"open_issues":904,"watchers":2427,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/3267"},"html":{"href":"https://github.com/dotnet/roslyn/pull/3267"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/3267"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/3267/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/3267/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/3267/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn/statuses/2edf59683f243be6bb65da60aaa985762f959455"}}}}