title: MVC Web Service returns - Microsoft SharePoint is not supported in 32-bit process
body: <p>I am Trying to implement DocX to replace information from documents on a Document Library in Sharepoint using a web service. I am having difficulties because when I run my project and try to send information to the api address I get the following error</p>
  
  <pre><code>Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable. 
  </code></pre>
  
  <p>While debugging the code breaks on the following line</p>
  
  <pre><code> using (SPSite site = new SPSite(siteurl))
  </code></pre>
  
  <p>I have found that I need to run the project on 64bit mode but if I choose that option the project does not run. I also found that the option Prefer 32bit cannot be checked but that option is disabled and not checked and finally in the IIS application Pool advance settings I need to turn into true the option Enable 32bit applications but it did not do anything.</p>
  
  <p>None of the earlier have worked for me, I would like to ask for some help on solving this issue.  </p>
  
  <p>I am working on Sharepoint 2013, Visual Studio 2012 and MVC 4.</p>
  
  <p>EDIT - </p>
  
  <p>API Function</p>
  
  <pre><code>public class DocumentController : ApiController
  {
  
      public DocModel Get(string docId, string docName, string docLibrary, string newDocLibrary)
      {
          DocModel document = new DocModel();
  
          try
          {
              string siteurl = "http://win-n1ni65gppp2/";
              using (SPSite site = new SPSite(siteurl))
              {
                  using (SPWeb web = site.OpenWeb())
                  {}
  
      }
          catch (Exception ex)
          {
              document.Message = ex.ToString() + "Perdistes";
              Console.Write(ex);
          }
  
          return document;
      }
  
  }
  </code></pre>
  
  <p>Exception Message while application is on Any CPU</p>
  
  <blockquote>
    <p>System.PlatformNotSupportedException: Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable. at Microsoft.SharePoint.Utilities.SPUtility.CheckFrameworkAndProcess() at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString() at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Local() at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm&amp; farm, Boolean&amp; isJoined) at Microsoft.SharePoint.Administration.SPFarm.get_Local() at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at SPDocumentAPI.Controllers.DocumentController.Get(String docId, String docName, String docLibrary, String newDocLibrary)</p>
  </blockquote>
  
  <p>Error Message when application is built under x64 platform in application properties</p>
  
  <blockquote>
    <p>Could not load file or assembly 'SPDocumentAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p>
  </blockquote>
  
  <p>Stack Trace</p>
  
  <blockquote>
    <p>[BadImageFormatException: Could not load file or assembly 'SPDocumentAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
       System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
       System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean forIntrospection) +16
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38</p>
    
    <p>[ConfigurationErrorsException: Could not load file or assembly 'SPDocumentAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
       System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
       System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
       System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
       System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean&amp; isRefAssemblyLoaded) +285
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516</p>
    
    <p>[HttpException (0x80004005): Could not load file or assembly 'SPDocumentAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254</p>
  </blockquote>