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
28
votes
5 answers

How to deal with Code Contracts warning CC1036 when using string.IsNullOrWhiteSpace?

I have the following code contract: public void F(string x) { Contract.Requires(!string.IsNullOrWhiteSpace(x)); throw new NotImplementedException(); } When compiling, I get the following warning: warning CC1036: Detected call to method…
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
27
votes
1 answer

Visual Studio 2015 InvalidProgramException in Unit Test With Fakes

I am using Visual Studio 2015 Enterprise RTM to write unit tests for a project that uses Unity Container. I have discovered that the simple act of adding a fakes assembly for Unity, not even actually using the fake, is sufficient to generate this…
25
votes
3 answers

How to run Roslyn instead csc.exe from command line?

After installing VS 2015, running csc.exe from command line causes this message to be displayed to console: This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer…
Dennis
  • 37,026
  • 10
  • 82
  • 150
24
votes
1 answer

Why do optional parameters get passed wrong values in Visual Studio 2015?

I found a weird behavior in VS2015 Here are the details: I have a .Net 4.6 project referencing a 3.5 assembly. This assembly defines in one of it's interfaces the following method that I was able to inspect using Resharper decompiler. void…
disklosr
  • 1,536
  • 17
  • 26
24
votes
2 answers

Is there any benefit of using the nameof operator instead of the CallerMemberNameAttribute to notify property changes in .NET 4.5.3?

With the advent of .NET 4.5.3, WPF developers now have three (or more) ways to notify the INotifyPropertyChanged Interface of property changes. Basically, my question is Which of the two methods introduced from.NET 4.5 onwards is the more efficient…
Sheridan
  • 68,826
  • 24
  • 143
  • 183
23
votes
1 answer

Visual Studio 2015 - Shared Projects Reference Tab Missing on Web Project

I upgraded to Visual Studio 2015 from our MSDN subscription because I was pretty excited to read about Shared Projects... No more managing 21382 nuget packages in our dependencies when all we want to do is reuse code. So I built a test shared…
Ryan Mann
  • 5,178
  • 32
  • 42
22
votes
1 answer

Error - could not find al.exe using sdkToolsPath

I migrated a Visual Studio 2012 solution to Visual Studio 2015. I'm working on Windows 10. The target .NET Framework of my solution is 4.5. I want to continue using that version. So I thought I have to uninstall the .NET framework 4.6. Error…
CPA
  • 2,923
  • 4
  • 30
  • 52
21
votes
1 answer

Expressions breaking code when compiled using VS2015 Update 1

After installing Visual Studio 2015 Update 1 on my machine I saw that some of my unit tests failed. After doing some investigation I was able to reduce the problem to this line of code: Expression> expression = t => t.X == 0…
Devedse
  • 1,801
  • 1
  • 19
  • 33
20
votes
2 answers

Stream.CopyToAsync with progress reporting - progress is reported even after copying finish

I've build a simple console applications that download files from the internet. Because I had problems with WebClient I decided to write my app using HttpClient. Basically I'm doing request to read headers, then using ReadAsStreamAsync I'm getting…
Misiu
  • 4,738
  • 21
  • 94
  • 198
20
votes
4 answers

Why does upcasting IDictionary to IEnumerable fail?
See the following code snippet: (IEnumerable)new Dictionary() The above cast will throw an invalid cast exception. Actually, IDictionary also indirectly implements IEnumerable, because it also implements…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
19
votes
3 answers

Put GC on hold during a section of code

Is there a way to put the GC on hold completely for a section of code? The only thing I've found in other similar questions is GC.TryStartNoGCRegion but it is limited to the amount of memory you specify which itself is limited to the size of an…
Ronan Thibaudau
  • 3,413
  • 3
  • 29
  • 78
18
votes
2 answers

Debugging symbols not loading in .NET standard project targeting .NET Framework

I am using Visual Studio 2017. I created a .NET Standard library (let this library be Lib1) project with two Target frameworks, netstandard2.0 and net46. Then I have another two projects... one is a "pure" .NET Framework 4.6 console project (lets…
jjamardo
  • 267
  • 3
  • 9
18
votes
1 answer

DNX: The current runtime target framework is not compatible with project

I am getting the following run-time error: [InvalidOperationException: The current runtime target framework is not compatible with 'TestDeployProject'. Current runtime Target Framework: 'DNX,Version=v4.5 (dnx45)' Type: CLR Architecture: x86 …
Dave New
  • 38,496
  • 59
  • 215
  • 394
17
votes
1 answer

Type.IsEnum Property in Portable Class Library

I'm trying to code in a Portable Class Library using ASP.NET Core 1.0, the following instruction: public static void WriteMessage(T value) { if (typeof(T).IsEnum) { Debug.Print("Is enum") } else { …
Karlok
  • 171
  • 1
  • 5
17
votes
3 answers

How to disable specific Code Analysis Warning for entire class

I'm trying to disable a code analysis rule across an entire class, but NOT for the entire project, just a single class. In the example below, the build generates a CA1822 warning because it thinks that the unit test methods should be static. The…
Suraj
  • 35,905
  • 47
  • 139
  • 250
1
2
3
29 30