Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 15.3 Simplifying null check

I have this code:

public UnityResolver(IUnityContainer container)
{
   if (container == null) throw new ArgumentNullException("container");
   _container = container;
}

Visual Studio shows 3 grey dots and suggests to simplify the null check.

It makes the method this:

_container = container ?? throw new ArgumentNullException("container");

That don't build...

What's going on here? Why does it think it can simplify this and why is it simplifying it to something that doesn't build.

The error is gives is:

1>L:\SL1-(SentiLAN)-SentiLAN v1 - Current System\SentilanCore\WEB API with Plugins\APITest2\App_Start\UnityConfig.cs(31,39,31,44): error CS1525: Invalid expression term 'throw'
1>L:\SL1-(SentiLAN)-SentiLAN v1 - Current System\SentilanCore\WEB API with Plugins\APITest2\App_Start\UnityConfig.cs(31,39,31,44): error CS1002: ; expected

enter image description here

like image 296
Stuart Avatar asked Aug 15 '17 09:08

Stuart


1 Answers

Its a compiler issue, code is valid. they updated the version and fixed the error in the latest update(few hours ago). you can download the update if the notification pops up or from the website.

Or simply update the Microsoft compiler version, since it wasn't included in the VS 2017...

Install-Package Microsoft.Net.Compilers -Version 2.3.0 is the latest i think

like image 153
Ulug Toprak Avatar answered Nov 01 '22 17:11

Ulug Toprak