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
Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable.
While debugging the code breaks on the following line
using (SPSite site = new SPSite(siteurl))
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.
None of the earlier have worked for me, I would like to ask for some help on solving this issue.
I am working on Sharepoint 2013, Visual Studio 2012 and MVC 4.
EDIT -
API Function
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;
}
}
Exception Message while application is on Any CPU
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& farm, Boolean& 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)
Error Message when application is built under x64 platform in application properties
Could not load file or assembly 'SPDocumentAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Stack Trace
[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& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[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& 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
[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