Questions tagged [.net-4.6]

.NET 4.6 (previously called .NET 4.5.3) is the latest framework release from Microsoft. It is a followup to .NET-4.5.2 which brings new features to both infrastructure (Roslyn, the compiler as a service) and new language features for both VB.net and C#

The .NET Framework 4.6 is the next version of the .NET Framework. Up until now we have been using .NET Framework 4.5.3, however since the payload includes significant features and improvements, the release number was bumped up the to clearly communicate the magnitude of changes. Note that in the Preview release, you’ll still see instances of “4.5.3” in the .NET Framework and Visual Studio version information. These will be updating these in future releases.

There are many great features in the .NET Framework 4.6 Preview. These range from new WPF features to RyuJIT as well as productivity enhancements in Visual Studio:

.NET Language Innovation

In this release, several new C# and Visual Basic language features help reduce boilerplate and clutter in everyday code, encourage a more declarative style of programming, and bring the two languages even closer together. The features listed below will be available to both languages in the final release. A few highlights are shared below. Checkout the C# and VB Team blogs for all the details.

  • Methods, getter-only properties etc. can now have a single expression as their body, just like lambdas.
  • Nameof provides a refactoring-safe way of getting the name of e.g. a parameter, member or type as a string.
  • Auto-properties can have initializers and no longer require setters.
  • Index initializers Inside an object initializer you can now initialize a specific index of the new object. C# only.
  • Exception filters let you look at an exception and decide whether to catch it with a given catch block.
  • Using null-conditional operators you can get a built-in null check while accessing and invoking members and indexers.
  • Using clauses for static classes bring their static members directly into scope, so you can. call e.g WriteLine() or Sqrt() without prefixing with the class name.
  • Await now works in catch and finally blocks, obviating some very tricky workarounds.
  • String interpolation: String interpolation provides a concise way of describing string templates that insert expressions into format strings (C# only at Preview, both VB and C# at RTM).

WPF Improvements and Roadmap

WPF has key improvements in this release:

  • Transparent child windows
  • Multi-image cursor files
  • Re-designed Blend experience
  • New set of Visual Diagnostics tools
  • Timeline tool in the Performance and Diagnostics hub

Windows Forms High DPI

Windows Forms High DPI support has been updated to include more controls. The .NET Framework 4.5.2 included high DPI support an initial set of controls.

This feature has been expanded to include: DataGridView, ComboBox, ToolStripComboBox, ToolStripMenuItem, Cursor, DomainUpDown, NumericUpDown, DataGridViewComboBoxColumn, DataGridViewColumn and ToolStripSplitButton types.

This is an opt-in feature. To enable it, set the EnableWindowsFormsHighDpiAutoResizing element to true in the application configuration (app.config) file:

<appSettings>
   <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

Next Generation JIT Compiler -- RyuJIT

This release includes a new version of RyuJIT, the 64-bit JIT Compiler. It is enabled by default for 64-bit processes.

  • Correctness – We’ve been focusing on fixing correctness bugs, using various Microsoft cloud workloads to validate RyuJIT. This approach has been working well, since the Microsoft cloud is a very heavy user of .NET.
  • Real-World Throughput – The Bing team recently started using RyuJIT on some of their search-related workloads. Based on their initial experiments, they have seen a 25% improvement in startup time, which is a significant win.
  • SIMD Improvements – We created the SIMD .NET library in unison with RyuJIT so that RyuJIT could optimize the SIMD types. Lately, we’ve been tuning our use of registers in the RyuJIT SIMD optimizations. CPUs can crunch numbers much faster in registers, since they are effectively memory on the CPU.

While the attempt to transition to the new JIT compiler as transparent as possible, there still may be compatibility issues. If your application produces an undesired behavior on RyuJIT, you can try disabling RyuJIT, which switches your application back to using the previous JIT to determine if the problems you are seeing are caused by RyuJIT.


CLR Performance Improvements

The assembly loader now uses memory more efficiency by unloading IL assemblies after a corresponding NGEN image is loaded. This change is a major benefit for virtual memory for large 32-bit apps (such as Visual Studio) and also saves physical memory.


Support for converting DateTime to or from Unix time

New methods have been added to support converting DateTime to or from Unix time. This can be necessary, for example, when converting time values between a JavaScript client and .NET server. The following APIs have been added to DateTimeOffset.

static DateTimeOffset FromUnixTimeSeconds(long seconds)
static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
long ToUnixTimeSeconds()
long ToUnixTimeMilliseconds()

ASP.NET Model Binding supports Task returning methods

ASP.NET Model Binding methods that were previously returning Task were not supported and threw an exception at runtime. With .NET Framework 4.6, if applications are deployed with such methods, these methods will now be executed correctly.0


Channel support for managed EventSource instrumentation

You now can use .NET EventSource instrumentation to log significant administrative or operational messages to the event log, in addition to any existing ETW sessions created on the machine

438 questions
17
votes
4 answers

How to mark identity column properly with Entity Framework 6.1?

I've seen many posts and answers regarding how to mark a field as the identity column. Many of them are outdated and are targeting older versions of Entity Framework. Some resources tell me to use an attribute on the…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
17
votes
3 answers

Shortest way to deserialize XmlDocument

I am looking for a clean and short way to deserialize a XmlDocument object. The closest thing I found was this but I am really wondering if there is no nicer way to do this (in .NET 4.5 or even 4.6) since I already have the XmlDocument. So currently…
silent
  • 14,494
  • 4
  • 46
  • 86
16
votes
2 answers

Can I get a pointer to a Span?

I have a (ReadOnly)Span from which I want to decode a string. Only in .NET Core 2.1 I have the new overload to decode a string from it without needing to copy the bytes: Encoding.GetString(ReadOnlySpan bytes); In .NET Standard 2.0 and…
Ray
  • 7,940
  • 7
  • 58
  • 90
16
votes
1 answer

Error While publishing Azure Cloud service with .net 4.6

Error : "The feature named NetFx46 that is required by the uploaded package is not available in the OS * chosen for the deployment."
Ihtsham Minhas
  • 1,415
  • 1
  • 19
  • 31
16
votes
2 answers

Always use the 'async' and 'await' keywords in asynchronous methods in a library?

Summary: In a library method, when should I use the async and await keywords instead of returning a Task directly? I believe my question is related to this one. However, that question is about .NET 4.0 and the TPL, while I'm using .NET 4.6 with the…
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
16
votes
2 answers

Is this closure combination behaviour a C# compiler bug?

I was investigating some strange object lifetime issues, and came across this very puzzling behaviour of the C# compiler: Consider the following test class: class Test { delegate Stream CreateStream(); CreateStream TestMethod(…
tg73
  • 415
  • 3
  • 10
15
votes
2 answers

Does C# store arrays larger than 512 longs (4096 bytes) differently?

I did some benchmarks with collection types implemented in the .NET Framework. From the Reference Source I know that List uses an array to store contents. To avoid resizing the array with every insertion, the array length gets doubled every time…
Franz Wimmer
  • 1,477
  • 3
  • 20
  • 38
15
votes
3 answers

.Net 4.6 AppContextSwitchOverrides not setting switches declared in config

I am trying to set the compatibility switch "Switch.System.Xml.IgnoreEmptyKeySequences" from an entry in an app.config (or web.config) file, but the override appears to be ignored. To remove the possibility of any strange configuration my existing…
Shed Magnet
  • 211
  • 2
  • 7
13
votes
1 answer

How does ServicePointManager.ReusePort and SO_REUSE_UNICASTPORT alleviate ephemeral port exhaustion?

Windows 10 and Windows Server 2016 introduced the SO_REUSE_UNICASTPORT socket option. It was made available for use in .NET starting from version 4.6 via the ServicePointManager.ReusePort static property. I'm suffering from ephemeral port exhaustion…
Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93
13
votes
1 answer

Nuget from portable class library: Value cannot be null or an empty string. Parameter name: profileValue

What I have I have Portable Class Library MyProj.Backend.Contracts.csproj with following project.json: { "supports": { "net46.app": {}, "uwp.10.0.app": {}, "dnxcore50.app": {} }, "dependencies": { "Microsoft.NETCore":…
Liero
  • 25,216
  • 29
  • 151
  • 297
13
votes
1 answer

WPF and touch - focus issue

I have a WPF .NET 4.6 application running on a Windows 8.1 tablet and for the last few days I've been struggling to make my app touch friendly to make it work as expected. My main problems are focus related, these affect several controls in my app.…
Yoav
  • 3,326
  • 3
  • 32
  • 73
13
votes
1 answer

How to set the .NET Version for VisualStudio2015 (Code)

Some people in our team are using VisualStudio 2015 while the rest is still using 2013 (both with ReSharper 9.1). The Target Framework in the project properties is set to .NET Framework 4.5.1. My Problem: I can still use code like public int X() =>…
TheWho
  • 485
  • 3
  • 17
13
votes
1 answer

Do I need to target my application to .NET 4.6 to take advantage of RyuJIT?

Reading from Announcing .NET Framework 4.6 it seems to imply that RyuJIT is only for .NET 4.6. Does that means I will need to re-target my applications to .NET 4.6 for RyuJIT to take effect?
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
12
votes
4 answers

Mixed WPF and winforms project DPI awareness

I have a C# program that uses both winforms and WPF and I'm struggling to get it to work in high DPI environments. Currently, if I remove all WPF projects from the solution and run it, it will scale fine, however as soon as I add any wpf back in…
Anya Hope
  • 1,301
  • 1
  • 17
  • 33
12
votes
1 answer

.Net 4.6 breaks XOR cipher pattern?

In .NET 4.5 this cipher worked perfectly on 32 and 64 bit architecture. Switching the project to .NET 4.6 breaks this cipher completely in 64-bit, and in 32-bit there's an odd patch for the issue. In my method "DecodeSkill", SkillLevel is the only…
Scotty
  • 259
  • 1
  • 12
1 2
3
29 30