2

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

John Saunders
  • 160,644
  • 26
  • 247
  • 397
JocisPR
  • 337
  • 1
  • 3
  • 10
  • That's server-side code and SharePoint is a 64-bit application. Did you add the server-side libraries to your application? If you did, your application **must** be 64-bit and located on the same servers as Sharepoint – Panagiotis Kanavos Mar 31 '14 at 14:57
  • Yeah, My Server is 64 bits, Sharepoint 2013 is 64 bits, Visual Studio 2012 version is 64 bit, I am developing on the same server. As for Libraries I am only using Microsoft.Sharepoint. – JocisPR Mar 31 '14 at 15:30
  • It's the *web application* that must be 64-bit, because Microsoft.SharePoint is a server-side library. Where is the code and what are the compilation/runtime errors? – Panagiotis Kanavos Mar 31 '14 at 15:34
  • The web application is running on Any CPU but the Prefer 32bit is not checked. If I set the application on 64bit do not open at all. I will post the exception message and stack trace on the main post – JocisPR Mar 31 '14 at 15:42
  • And what is SPDocumentAPI? SharePoint has no such library and any third-party libraries would be compiled as x64 anyway. If it's another project in your solution, it has to be set to x64 as well – Panagiotis Kanavos Mar 31 '14 at 15:50
  • Sorry SPDocumentAPI is the project name. I am running the code on a project named SPDocumentAPI – JocisPR Mar 31 '14 at 15:55
  • If SPDocumentAPI is the name of your MVC project, you probably need to clean the entire solution because IIS is loading a 32-bit dll somewhere. The error is specific: either SPDocumentAPI or one of the libraries it references is 32-bit – Panagiotis Kanavos Mar 31 '14 at 16:00
  • Thanks. I have cleaned the project but no luck. I will be verifying the libraries so I can check them out of the project. – JocisPR Mar 31 '14 at 16:08
  • I created a new mvc4 project and build it as a x64 platform target, I got Error Message when application is built under x64 platform in application properties error – JocisPR Mar 31 '14 at 17:38
  • Nothing works. I just want to be able to create a new word document from a existing word template using a custom web part I created for sharepoint. – JocisPR Apr 01 '14 at 12:33

1 Answers1

5

Well the project was running on IIS Express and it seems that IIS Express does not compile 64bit applications on Visual Studio 2012.

I found this link that explains how to add some changes to the registry.

In the end just run the following code on the command prompt and restart the server.

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\WebProjects /v Use64BitIISExpress /t REG_DWORD /d 1
Community
  • 1
  • 1
JocisPR
  • 337
  • 1
  • 3
  • 10