Search code examples
c#visual-studio-codeargumentnullexception

C# ArgumentNullException type or namespace could not be found. VS Code


Part Of My Code:

 public void Move(Point newLocation)
    {
        if (newLocation == null)
            throw new ArgumentNullException("newLocation");

        Move(newLocation.X, newLocation.Y);
    }

I get this as a Error:

The type or namespace name 'ArgumentNullException' could not be found (are you missing a using directive or an assembly reference?)

Is there something wrong with my c# code. Could this be a VS Code C# support extension bug?

I am a beginner to c# please explain


Solution

  • ArgumentNullException is in the "System" namespace. So either fully-qualify the name,

    throw new System.ArgumentNullException("newLocation");
    

    or add

    using System;
    

    to the top of your C# file or your namespace.