2

A quote out of What's New in 4.6

For apps that target the .NET Framework 4.6 RC, Task and Task<TResult> objects inherit the culture and UI culture of the calling thread. The behavior of apps that target previous versions of the .NET Framework, or that do not target a specific version of the .NET Framework, is unaffected.

I always thought that there only exists v4.0.30319 at the assembly level for 4.0, 4.0.1, 4.0.2, 4.0.3, 4.5, 4.5.1, 4.5.2 and 4.6 -- and that 4.6 is only an inplace update for 4.0-4.5.2?

To my current knowledge the specified version in the app.config file only triggers a message box if the SKU is not installed at all -- how can this affect how assemblies behave?

Community
  • 1
  • 1
springy76
  • 3,706
  • 2
  • 24
  • 46
  • 1
    Too early for me to try, but the simple explanation is that it pays attention to the [TargetFrameworkAttribute](http://referencesource.microsoft.com/#mscorlib/system/runtime/versioning/targetframeworkattribute.cs,6a3c751444d92d65,references). As you can tell from the references, it is already used to turn features on. – Hans Passant May 05 '15 at 13:38
  • @HansPassant this would mean the framework is full of runtime version checks (maybe using `AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName`?) simulating older versions? I yet did not spot how `System.Uri` decides to behave differently if the app targets 4.5 or higher. – springy76 May 05 '15 at 15:03

1 Answers1

1

This page says it all,

https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.110).aspx

Culture and task-based asynchronous operations

The task-based asynchronous programming pattern uses Task and Task objects to asynchronously execute delegates on thread pool threads. The specific thread on which a particular task runs is not known in advance, but is determined only at runtime.

For apps the target the .NET Framework 4.6 RC or later versions, culture is part of an asynchronous operation's context. In other words, starting with apps the target the .NET Framework 4.6 RC, asynchronous operations by default inherit the values of the CurrentCulture and CurrentUICulture properties of the thread from which they are launched. If the current culture or current UI culture differs from the system culture, the current culture crosses thread boundaries and becomes the current culture of the thread pool thread that is executing an asynchronous operation.

The following example provides a simple illustration. It uses the TargetFrameworkAttribute attribute to target the .NET Framework 4.6 RC. The example defines a Func delegate, formatDelegate, that returns some numbers formatted as currency values. The example changes the current system culture to either French (France) or, if French (France) is already the current culture, English (United States). It then:

  • Invokes the delegate directly so that it runs synchronously on the main app thread.
  • Creates a task that executes the delegate asynchronously on a thread pool thread.
  • Creates a task that executes the delegate synchronously on the main app thread by calling the Task.RunSynchronously method.

You can see from the code sample to see how to explicitly mark your program as .NET 4.6 targeted. Then CLR uses the new behavior. For all assemblies without such an attribute, or the value is not 4.6, the old behavior is kept.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • and how does the assembly referenced by the program behave differently now? For example System.Uri (in System.dll) starts to preserve path segments that have more than two consecutive dots (such as http://localhost/dir1/.../dir2) starting with 4.5 -- LinqPad (which targets 4.0) doesn't preserve them, but is using the very same System.dll which is at version 4.5.2 here. (I can't spot any framework detecting code in System.Uri using ILSpy) – springy76 May 05 '15 at 14:56
  • There can be many breaking changes and each has its own remediation tips. I am not able to give you a universal solution, neither Microsoft. – Lex Li May 06 '15 at 00:19
  • You still have not answered my question by any means. When I have installed 4.6 then on my system there is no 4.0 or 4.5 anymore. How is it done? What does the TargetFrameworkAttribute change? – springy76 May 11 '15 at 10:26
  • @spring76, the .NET 4.0/4.5 behavior remains in .NET 4.6, while it is possible to enable new behavior by changing the TargetFrameworkAttribute in an assembly. What runtime you specify in app.config won't affect that at all. – Lex Li Mar 09 '16 at 13:50