Visual Studio 2017 15.3 Simplifying null check

Viewed 1808

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

1 Answers
Related