{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/4889","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/4889/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/4889/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/4889/events","html_url":"https://github.com/dotnet/roslyn/issues/4889","id":103924162,"number":4889,"title":".Net 4.6 optimizations breaking on 4.5.2 servers","user":{"login":"NickCraver","id":454813,"avatar_url":"https://avatars.githubusercontent.com/u/454813?v=3","gravatar_id":"","url":"https://api.github.com/users/NickCraver","html_url":"https://github.com/NickCraver","followers_url":"https://api.github.com/users/NickCraver/followers","following_url":"https://api.github.com/users/NickCraver/following{/other_user}","gists_url":"https://api.github.com/users/NickCraver/gists{/gist_id}","starred_url":"https://api.github.com/users/NickCraver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickCraver/subscriptions","organizations_url":"https://api.github.com/users/NickCraver/orgs","repos_url":"https://api.github.com/users/NickCraver/repos","events_url":"https://api.github.com/users/NickCraver/events{/privacy}","received_events_url":"https://api.github.com/users/NickCraver/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-08-30T13:38:57Z","updated_at":"2016-01-20T14:59:04Z","closed_at":"2015-08-30T16:42:03Z","body":"We hit a break when rolling out .Net 4.6 at Stack Overflow which I [did a sanity check on here](https://github.com/dotnet/roslyn/issues/1103#issuecomment-136125635). This is the `Array<T>` optimization in play:\r\n\r\n<img width=\"509\" alt=\"screen shot 2015-08-30 at 6 27 52 am\" src=\"https://cloud.githubusercontent.com/assets/454813/9566807/26ac3ef0-4ee1-11e5-86ac-8f12c7c1a7ff.png\">\r\n\r\nThe optimization itself isn't as important as the class it uses: `Array.Empty<T>`, which **doesn't exist in 4.5.2**. This creates an overlapping set of issues of builds and runtime that resulted in a break for us. I first upgraded our canary servers, but not 100% correctly - the .Net 4.5.2 reference assemblies were not present. This resulted in the following layout:\r\n\r\nBuild server: **.Net 4.6** (reference assemblies up through 4.5.1, but *not* 4.5.2)\r\nProject target: **.Net 4.5.2**\r\nRuntime server: **.Net 4.5.2**\r\n\r\nSo what happened is that the build server did not find .Net 4.5.2 reference assemblies and happily resolved .Net 4.6 assemblies instead. The only hint of this is a build warning, not an error. (Aside: You could easily, IMO, argue that .Net 4.5.1 is a much safer fallback resolution here. Separately, you could argue the commonplace of these build warnings makes them weaker justification in breaks.) Since the compiled-against assembly is what Roslyn checks against in [`GetWellKnownTypeMember()`](https://github.com/dotnet/roslyn/blob/051ad4381100859442af93e16d8d8edbb681b05f/src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs#L40), this mean that regardless of the targeted framework, a .Net 4.6+ optimization was used *in the IL*.\r\n\r\nI think there's another discussion to be had on forward vs. backwards resolution on a target failure (or having the default actually be an error, not a warning), but let's scope this issue more to this specific problem. In discussion on the other issue, @FransBouma [made what I think is an excellent point](https://github.com/dotnet/roslyn/issues/1103#issuecomment-136133291):  \r\nWhy isn't this a JIT optimization? \r\n\r\nIt makes much more sense here, at least on the surface, that a more well-informed JIT can make a better decision here given the types actually available at runtime. What was the reasoning for this being in roslyn instead of a runtime optimization? The net result currently is a **runtime-only** break as a result of this optimization, seen here:\r\n\r\n```\r\nSystem.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'.\r\n   at Calculon.Web.Scheduled.Tasks.ReportRedisInfoToBosunTask.<Execute>d__5.MoveNext()\r\n   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Calculon.Web.Scheduled.Tasks.ReportRedisInfoToBosunTask.Execute(DateTime started)\r\n   at Calculon.Web.Scheduled.ScheduledTasks.<RunScheduledTaskAsync>d__7.MoveNext()\r\n```\r\n\r\nTo me, the runtime-only nature of the break makes it quite a bit more serious for people upgrading to .Net 4.6 and (quite literally) changing nothing else. What was the thinking here? Does JIT not make sense for other reasons that aren't so apparent? If this was reasoned through and consciously decided, I'd love to see and read the discussions. I simply can't find them, though I have searched."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/173228640","html_url":"https://github.com/dotnet/roslyn/issues/4889#issuecomment-173228640","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/4889","id":173228640,"user":{"login":"niemyjski","id":1020579,"avatar_url":"https://avatars.githubusercontent.com/u/1020579?v=3","gravatar_id":"","url":"https://api.github.com/users/niemyjski","html_url":"https://github.com/niemyjski","followers_url":"https://api.github.com/users/niemyjski/followers","following_url":"https://api.github.com/users/niemyjski/following{/other_user}","gists_url":"https://api.github.com/users/niemyjski/gists{/gist_id}","starred_url":"https://api.github.com/users/niemyjski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemyjski/subscriptions","organizations_url":"https://api.github.com/users/niemyjski/orgs","repos_url":"https://api.github.com/users/niemyjski/repos","events_url":"https://api.github.com/users/niemyjski/events{/privacy}","received_events_url":"https://api.github.com/users/niemyjski/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T14:59:03Z","updated_at":"2016-01-20T14:59:03Z","body":"This needs to be fixed NOW. How the heck has this issue been open for 6 months. We just upgraded our build server on appveyor to .NET 4.6 (VS 2015 build image) and changed nothing. Now all of our customers who consume our nuget packages are getting this error. Who the heck thought this was acceptable to not take action for the past 6 months. I'd say this is a HUGE Compatibility issue."}}