title: Error Creating Site Collection Programmatically
body: <p>I have a console application that is going to be used to parse an input file and create site collections based on the input. It is being run on a WFE in the farm, by a farm admin account. When attempting to add a site collection to a web application with a valid user an ArgumentException is thrown deep in the stack with an error message of "0x80070057". I have verified that if an invalid account is used the correct SPException indicating that the user is not found is thrown, and that all other parameters are correct.</p>
  
  <p>Code:</p>
  
  <pre><code>    internal static void CreateOrgSite(String path)
      {
          SPWebApplication webApp = SPWebApplication.Lookup(new Uri(ConfigurationManager.AppSettings["WebAppBaseUrl"]));
  
          String user = Environment.UserDomainName + "\\" + Environment.UserName;
          String newSiteUrl = GetCompleteUrl(path);
          webApp.Sites.Add(newSiteUrl, user, String.Empty);
  
      }
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <pre><code>System.ArgumentException: &lt;nativehr&gt;0x80070057&lt;/nativehr&gt;&lt;nativestack&gt;&lt;/nativestack&gt;
      at Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWebInternal(String bstrUrl, Guid&amp; pguidID, String&amp; pbstrRequestAccessEmail, UInt32&amp; pwebVersion, String&amp; pbstrServerRelativeUrl, UInt32&amp; pnLanguage, UInt32&amp; pnLocale, String&amp; pbstrDefaultTheme, String&amp; pbstrDefaultThemeCSSUrl, String&amp; pbstrThemedCssFolderUrl, String&amp; pbstrAlternateCSSUrl, String&amp; pbstrCustomizedCssFileList, String&amp; pbstrCustomJSUrl, String&amp; pbstrAlternateHeaderUrl, String&amp; pbstrMasterUrl, String&amp; pbstrCustomMasterUrl, String&amp; pbstrSiteLogoUrl, String&amp; pbstrSiteLogoDescription, Object&amp; pvarUser, Boolean&amp; pvarIsAuditor, Int32&amp; plSiteFlags, Boolean&amp; pbOverwriteMUICultures, Boolean&amp; pbMUIEnabled, String&amp; pbstrAlternateMUICultures, Int32&amp; puiVersion, Int16&amp; pnClientTag)
      at Microsoft.SharePoint.Library.SPRequest.OpenWebInternal(String bstrUrl, Guid&amp; pguidID, String&amp; pbstrRequestAccessEmail, UInt32&amp; pwebVersion, String&amp; pbstrServerRelativeUrl, UInt32&amp; pnLanguage, UInt32&amp; pnLocale, String&amp; pbstrDefaultTheme, String&amp; pbstrDefaultThemeCSSUrl, String&amp; pbstrThemedCssFolderUrl, String&amp; pbstrAlternateCSSUrl, String&amp; pbstrCustomizedCssFileList, String&amp; pbstrCustomJSUrl, String&amp; pbstrAlternateHeaderUrl, String&amp; pbstrMasterUrl, String&amp; pbstrCustomMasterUrl, String&amp; pbstrSiteLogoUrl, String&amp; pbstrSiteLogoDescription, Object&amp; pvarUser, Boolean&amp; pvarIsAuditor, Int32&amp; plSiteFlags, Boolean&amp; pbOverwriteMUICultures, Boolean&amp; pbMUIEnabled, String&amp; pbstrAlternateMUICultures, Int32&amp; puiVersion, Int16&amp; pnClientTag)
      at Microsoft.SharePoint.SPWeb.InitWebPublic()
      at Microsoft.SharePoint.SPWeb.get_ServerRelativeUrl()
      at Microsoft.SharePoint.SPWeb.get_Url()
      at Microsoft.SharePoint.SPUser.InitMember()
      at Microsoft.SharePoint.SPUser..ctor(SPWeb web, SPSecurableObject scope, String strIdentifier, Object[,] arrUsersData, UInt32 index, Int32 iByParamId, String strByParamSID, String strByParamEmail, SPUserCollectionType userCollectionType, Boolean isSiteAuditor)
      at Microsoft.SharePoint.SPUser..ctor(SPWeb web, SPSecurableObject scope, String strIdentifier, Object[,] arrUsersData, UInt32 index, Int32 iByParamId, String strByParamSID, String strByParamEmail, SPUserCollectionType userCollectionType)
      at Microsoft.SharePoint.SPUserCollection.GetByLoginNoThrow(String loginName)
      at Microsoft.SharePoint.SPUserCollection.get_Item(String loginName)
      at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPContentDatabase database, SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, String quotaTemplate, String sscRootWebUrl, Boolean useHostHeaderAsSiteName)
      at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
      at Microsoft.SharePoint.Administration.SPSiteCollection.Add(String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
      at Microsoft.SharePoint.Administration.SPSiteCollection.Add(String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail)
      at Microsoft.SharePoint.Administration.SPSiteCollection.Add(String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail)
      SharePoint\SharePointDataAccess.cs(25,0): at ImportOrgsUsers.SharePoint.SharePointDataAccess.CreateOrgSite(String path)
  </code></pre>