title: "Value does not fall within the expected range" when adding securables to a SQL Server database user
body: <p>I'm trying to assign securables against a user, but every time I try and grant permissions on a table-valued function, I get the error:</p>
  
  <blockquote>
    <p>Key cannot be null.<br>
    Parameter name: key (mscorlib)</p>
  </blockquote>
  
  <p>There is no error when adding stored procedures, views or tables, and using T-SQL to grant the permissions works fine. I've tried this on different databases on the same server and two instances of SQL Server 2016 with exactly the same errors.</p>
  
  <ul>
  <li>SQL Server 2016 v13.0.4202.2 </li>
  <li>SSMS v16 build 13.0.15900.1<br>
  <strong>Edit:</strong> Upgrade to SSMS 17.1 build 14.0.17119.0 didn't help</li>
  </ul>
  
  <p>As a side note (possibly related), I'm also getting an error when trying to list all objects belonging to a schema via <em>User > Securables > Search > All objects belonging to the schema</em>.  It doesn't matter which schema I pick, the dialog closes with the error:</p>
  
  <blockquote>
    <p>Value does not fall within the expected range. (SqlMgmt)</p>
  </blockquote>
  
  <p>More information:</p>
  
  <p><a href="https://i.stack.imgur.com/prA8J.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/prA8J.jpg" alt="Key cannot be null. Parameter name: key (mscorlib)"></a></p>
  
  <p>Stack trace from the "Technical details" button:</p>
  
  <pre><code>===================================
  
  Key cannot be null.
  Parameter name: key (mscorlib)
  
  ------------------------------
  Program Location:
  
     at System.Collections.Hashtable.ContainsKey(Object key)
     at System.Collections.Hashtable.Contains(Object key)
     at System.Collections.Specialized.HybridDictionary.Contains(Object key)
     at Microsoft.SqlServer.Management.SqlMgmt.PermissionsData.SecurableColumnParent.ApplyRevokes(SqlSmoObject obj)
     at Microsoft.SqlServer.Management.SqlMgmt.PermissionsData.Principal.ApplyChanges(String principalName, Server server)
     at Microsoft.SqlServer.Management.SqlMgmt.PermissionsDatabasePrincipal.OnRunNow(Object sender)
     at Microsoft.SqlServer.Management.SqlMgmt.PanelExecutionHandler.Run(RunType runType, Object sender)
     at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.DoPreProcessExecutionAndRunViews(RunType runType)
     at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.ExecuteForSql(PreProcessExecutionInfo executionInfo, ExecutionMode&amp; executionResult)
     at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.Microsoft.SqlServer.Management.SqlMgmt.IExecutionAwareSqlControlCollection.PreProcessExecution(PreProcessExecutionInfo executionInfo, ExecutionMode&amp; executionResult)
     at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.RunNow(RunType runType, Object sender)
  </code></pre>