{"action":"created","issue":{"url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/871","repository_url":"https://api.github.com/repos/NuGet/NuGet.Client","labels_url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/871/labels{/name}","comments_url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/871/comments","events_url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/871/events","html_url":"https://github.com/NuGet/NuGet.Client/pull/871","id":177204538,"number":871,"title":"Properly request DTE service from the components service provider","user":{"login":"kzu","id":169707,"avatar_url":"https://avatars.githubusercontent.com/u/169707?v=3","gravatar_id":"","url":"https://api.github.com/users/kzu","html_url":"https://github.com/kzu","followers_url":"https://api.github.com/users/kzu/followers","following_url":"https://api.github.com/users/kzu/following{/other_user}","gists_url":"https://api.github.com/users/kzu/gists{/gist_id}","starred_url":"https://api.github.com/users/kzu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzu/subscriptions","organizations_url":"https://api.github.com/users/kzu/orgs","repos_url":"https://api.github.com/users/kzu/repos","events_url":"https://api.github.com/users/kzu/events{/privacy}","received_events_url":"https://api.github.com/users/kzu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NuGet/NuGet.Client/labels/cla-already-signed","name":"cla-already-signed","color":"009800"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-15T15:12:47Z","updated_at":"2016-09-16T09:50:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/NuGet/NuGet.Client/pulls/871","html_url":"https://github.com/NuGet/NuGet.Client/pull/871","diff_url":"https://github.com/NuGet/NuGet.Client/pull/871.diff","patch_url":"https://github.com/NuGet/NuGet.Client/pull/871.patch"},"body":"The previous approach failed if the MEF component happened to be\r\ninstantiated from a background thread (i.e. another MEF component\r\nrequested in a background thread depended these exports). Since\r\nMEF components aren't guaranteed to initialize on the UI thread,\r\nthis caused heard to track and unfriendly errors, such as\r\nNuGet/Home#3419.\r\n\r\nThe requirement came from the helper class which used a static\r\nservice locator and therefore had no way of knowing if it was\r\nbeing properly invoked, and therefore resorted to just throwing\r\nif not.\r\n\r\nThis fix changes the way these services are requested from the\r\nMEF components so that they use the built-in mechanism provided\r\nby VSMEF to retrieve VS services properly from a MEF component:\r\nthe IServiceProvider import.\r\n\r\nSince the helper does not need to retrieve the service itself\r\nanymore, it receives the DTE as a parameter instead.\r\n\r\nThis fixes NuGet/Home#3419\r\n\r\nThe previous issue can be easily reproduced with the following\r\nVS package code:\r\n\r\n\t[ProvideAutoLoad(UIContextGuids.SolutionExists)]\r\n\t[PackageRegistration(UseManagedResourcesOnly = true)]\r\n\t[Guid(PackageGuidString)]\r\n\tpublic sealed class NuGetBreakingPackage : Package\r\n\t{\r\n\t\tpublic const string PackageGuidString = \"3FF684D3-61BF-417C-A1C0-17CD9B81BFE6\";\r\n\r\n\t\tprotected override void Initialize()\r\n\t\t{\r\n\t\t\tbase.Initialize();\r\n\r\n\t\t\tvar components = (IComponentModel)GetService(typeof(SComponentModel));\r\n\r\n\t\t\tSystem.Threading.Tasks.Task.Run(() =>\r\n\t\t\t{\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tvar solution = components.DefaultExportProvider.GetExportedValue<object>(\"NuGet.PackageManagement.ISolutionManager\");\r\n\t\t\t\t}\r\n\t\t\t\tcatch (Exception ex)\r\n\t\t\t\t{\r\n\t\t\t\t\tDebug.Fail(ex.ToString());\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}"},"comment":{"url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/comments/247561510","html_url":"https://github.com/NuGet/NuGet.Client/pull/871#issuecomment-247561510","issue_url":"https://api.github.com/repos/NuGet/NuGet.Client/issues/871","id":247561510,"user":{"login":"kzu","id":169707,"avatar_url":"https://avatars.githubusercontent.com/u/169707?v=3","gravatar_id":"","url":"https://api.github.com/users/kzu","html_url":"https://github.com/kzu","followers_url":"https://api.github.com/users/kzu/followers","following_url":"https://api.github.com/users/kzu/following{/other_user}","gists_url":"https://api.github.com/users/kzu/gists{/gist_id}","starred_url":"https://api.github.com/users/kzu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzu/subscriptions","organizations_url":"https://api.github.com/users/kzu/orgs","repos_url":"https://api.github.com/users/kzu/repos","events_url":"https://api.github.com/users/kzu/events{/privacy}","received_events_url":"https://api.github.com/users/kzu/received_events","type":"User","site_admin":false},"created_at":"2016-09-16T09:50:12Z","updated_at":"2016-09-16T09:50:12Z","body":"I don't have a problem with that, but switching threads isn't free and as\nproven in the linked issue, it's obviously not needed for this particular\nnarrow case of retrieving the version.\n\nI doubt changing this to use JTF will change the intention of not fixing\nthis in nuget though. We'll likely fix it in Xamarin, and it will then be\njust a matter of time until some other component triggers this same issue.\n\nGiven how non-obvious it was for me to find the cause (even if this is not\nthe root cause), I'd totally take the opportunity to fix it here.\n\nOn Fri, Sep 16, 2016, 2:23 AM Justin Emgarten <notifications@github.com>\nwrote:\n\n> The goal of throwing if not on the UI thread is to ensure that this code\n> fails consistently if there is a problem, which there appears to be here\n> since DTE should only be used from the UI thread per the VS threading\n> guidelines.\n>\n> This change would probably solve the issue, but it seems like a JTF should\n> be used here to ensure that this gets onto the UI thread to perform the DTE\n> operations.\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/NuGet/NuGet.Client/pull/871#issuecomment-247520696>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AAKW6zIdKSB3NnaiL_I4fGFiKw_bDGPVks5qqifAgaJpZM4J9_KA>\n> .\n>\n-- \n/kzu from mobile\n"}}
{"actor":{"display_login":"kzu"}}