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
132
votes
10 answers

Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater - Error on one machine but works on another

When using Visual Studio Enterprise 16.3.7 on two separate machines, one builds fine and the other machine throws the error: Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater. This can easily be…
Ogglas
  • 62,132
  • 37
  • 328
  • 418
92
votes
6 answers

Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

I am trying to target .NET 4.6 and also take advantage of the latest C# version by changing the C# language version to 6. However during compilation I got this error: Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or…
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
78
votes
4 answers

HttpClientFactory.Create vs new HttpClient

I am curious what is the purpose of the HttpClientFactory class. There is no description of why it exists on MSDN (see link). There are Create methods with more specialized arguments, but mostly I wonder what is the difference between the call with…
Bart Verkoeijen
  • 16,545
  • 7
  • 52
  • 56
73
votes
3 answers

How do the semantics of AsyncLocal differ from the logical call context?

.NET 4.6 introduces the AsyncLocal class for flowing ambient data along the asynchronous flow of control. I've previously used CallContext.LogicalGet/SetData for this purpose, and I'm wondering if and in what ways the two are semantically…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
66
votes
1 answer

How to build .NET 4.6 Framework app without Visual Studio installed?

Until now, I could build .NET 4.5.2 using command line c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild MySolution.sln The only what I need to install on a computer was .NET Framework and Visual Studio 2010 shell. Now I consider upgrading to…
Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
61
votes
3 answers

What is the point of .NET 4.6's Task.CompletedTask?

This blog post mentions the new Task APIs, including a new Task.CompletedTask property introduced in .NET 4.6. Why was this added? How is this better than, say, Task.FromResult(whatever)?
Gigi
  • 28,163
  • 29
  • 106
  • 188
58
votes
9 answers

Visual Studio 2013 and .NET 4.6

I'm trying to set the 4.6 .NET framework for my project and in the settings, as it wasn't listed, I chose the last option - to install more frameworks. That directed me to a page where I selected VS2013, clicked on .NET 4.6 and downloaded the…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
55
votes
4 answers

How can I change a .NET standard library to a .NET framework library?

I'm writing a class library for a simple parser in C#. When I first created it, I used .NET standard 2.0, but now I need to migrate it to .NET 4.6 both to conform to the other projects in my solution and in order to use NUnit. I tried to follow the…
Edward Minnix
  • 2,889
  • 1
  • 13
  • 26
37
votes
1 answer

GC behavior when pinning an object

While browsing through the code of PinnableObjectCache from mscorlib, I've encountered the following code: for (int i = 0; i < m_restockSize; i++) { // Make a new buffer. object newBuffer = m_factory(); // Create space between the…
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
35
votes
6 answers

TFS 2013 building .NET 4.6 / C# 6.0

We use TFS 2013 to as our build server. I've started a C# 6.0 project and I am trying to get it to build. I am using the new null-conditional operators, and my build chokes. I've tried installing several things on the TFS server, including the…
zimdanen
  • 5,508
  • 7
  • 44
  • 89
35
votes
1 answer

RyuJit producing incorrect results

After recently upgrading to .net 4.6 we discovered a bug where RyuJit produces incorrect results, we were able to work around the issue for now by adding useLegacyJit enabled="true" to the app.config. How can I debug the machine code generated by…
BrandonAGr
  • 5,827
  • 5
  • 47
  • 72
34
votes
3 answers

Garbage Collection and Parallel.ForEach Issue After VS2015 Upgrade

I have some code to process several million data rows in my own R-like C# DataFrame class. There's a number of Parallel.ForEach calls for iterating over the data rows in parallel. This code has been running for over a year using VS2013 and .NET…
32
votes
5 answers

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater

There is a similar question to this here but I believe that involves a different cause. I moved a class from a newer project into an older project. Both were targeting .net 4.6 however after the move I received the following error on build. Feature…
TheColonel26
  • 2,618
  • 7
  • 25
  • 50
29
votes
5 answers

How to install .NET 4 Framework in Windows 10

How can I install the .NET 4.0 Framework in Windows 10? .NET 4.6 is already installed but I want to have .NET 4 Framework (without modifying the registry). Turning on and off Windows features in control panel does not have any effect.
Ho Pam
  • 435
  • 1
  • 4
  • 6
29
votes
2 answers

TaskContinuationOptions.RunContinuationsAsynchronously and Stack Dives

In this blog post, Stephan Toub describes a new feature that will be included in .NET 4.6 which adds another value to the TaskCreationOptions and TaskContinuationOptions enums called RunContinuationsAsynchronously. He explains: "I talked about a…
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
1
2 3
29 30