MVC Web服务返回 - 32位进程不支持Microsoft SharePoint

Joc*_*sPR 2 c# sharepoint

我正在尝试使用Web服务实现DocX以替换Sharepoint中文档库中的文档中的信息.我遇到了困难,因为当我运行我的项目并尝试将信息发送到api地址时,我收到以下错误

Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable. 
Run Code Online (Sandbox Code Playgroud)

在下一行调试代码时会中断

 using (SPSite site = new SPSite(siteurl))
Run Code Online (Sandbox Code Playgroud)

我发现我需要在64位模式下运行该项目,但如果我选择该选项,项目就不会运行.我还发现无法检查选项Prefer 32bit但是该选项已禁用且未检查,最后在IIS应用程序池提前设置中我需要将其设置为true选项启用32位应用程序,但它没有做任何事情.

以前没有一个对我有用,我想请求帮助解决这个问题.

我正在开发Sharepoint 2013,Visual Studio 2012和MVC 4.

编辑 -

API函数

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;
    }

}
Run Code Online (Sandbox Code Playgroud)

应用程序在任何CPU上时的异常消息

System.PlatformNotSupportedException:32位进程不支持Microsoft SharePoint.请验证您是否在64位可执行文件中运行.微软.SharePoint.Utilities.SPUtility.CheckFrameworkAndProcess()Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString()at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Local()at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm&farm, Boolean&isJoined)位于Microsoft.SharePoint.Administration.SPFarm.get_Local()的Microsoft.SharePoint.SPSite..ctor(String requestUrl)at SPDocumentAPI.Controllers.DocumentController.Get(String docId,String docName,String docLibrary,String newDocLibrary)

在应用程序属性中的x64平台下构建应用程序时出现错误消息

无法加载文件或程序集"SPDocumentAPI"或其依赖项之一.尝试加载格式不正确的程序.

堆栈跟踪

[BadImageFormatException:无法加载文件或程序集'SPDocumentAPI'或其依赖项之一.尝试加载格式不正确的程序.] 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 assemblySecuri ty,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:无法加载文件或程序集"SPDocumentAPI"或其依赖项之一.尝试加载格式不正确的程序.] 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):无法加载文件或程序集"SPDocumentAPI"或其依赖项之一.尝试加载格式不正确的程序.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+9915300 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr ,HttpContext context)+254

Joc*_*sPR 5

那么该项目在IIS Express上运行,似乎IIS Express无法在Visual Studio 2012上编译64位应用程序.

我找到了这个链接,解释了如何向注册表添加一些更改.

最后,只需在命令提示符下运行以下代码,然后重新启动服务器.

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\WebProjects /v Use64BitIISExpress /t REG_DWORD /d 1
Run Code Online (Sandbox Code Playgroud)