在WCF中使用FaceSDK.NET程序集的OutOfMemoryException

时间:2013-11-28 14:46:55

标签: .net wcf

我有一个WCF项目,它引用了2个项目。

  1. 图书馆项目(A)。
  2. 数据合同图书馆(B) - 一个单独的项目。
  3. 此项目是FaceSDK.NET第三方图书馆的参考。我在另一个项目中使用了这个FaceSDK.NET dll文件。但它需要插入App.config

    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        <supportedRuntime version="v2.0.50727"></supportedRuntime>
    </startup>
    

    我想在我的WCF项目中使用库项目中的功能。当我构建项目时,它构建良好。但是当它在WCF测试客户端上运行时,它会产生如下错误。

    Server Error in '/' Application.
    Exception of type 'System.OutOfMemoryException' was thrown. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    [OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
    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: Exception of type 'System.OutOfMemoryException' was thrown.]
    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) +258   
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
    
    [HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874840
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101  
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
    

    有人认为这是由于目标平台不兼容。我试图将它保持在一个平台上。我也尝试添加一个App.confing文件,但没有用。非常感谢帮助。

    this帖子中,有一个类似的问题,但这与WCF有关。

    编辑:

    我会添加更多信息。这个项目A使用EmguCV包装器。当我将OpenCV文件(这些是500MB)显式添加到WCF服务的bin时,它会出现上述错误。当我删除这些文件然后只放置项目引用时,错误有点不同。

        Error: Cannot obtain Metadata from http://localhost:4039/ThahavuruFaceRecognitionService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:4039/ThahavuruFaceRecognitionService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:4039/ThahavuruFaceRecognitionService.svc'. The requested service, 'http://localhost:4039/ThahavuruFaceRecognitionService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:4039/ThahavuruFaceRecognitionService.svc There was an error downloading 'http://localhost:4039/ThahavuruFaceRecognitionService.svc'. The request failed with the error message:-- 
    Server Error in '/' Application.
    --------------------------------------------------------------------------------
    
    Could not load file or assembly 'FaceSDK.NET' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.BadImageFormatException: Could not load file or assembly 'FaceSDK.NET' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Assembly Load Trace: The following information can be helpful to determine why the assembly 'FaceSDK.NET' could not be loaded.
    
    === Pre-bind state information ===LOG: User = ana\anaLOG: DisplayName = FaceSDK.NET (Partial)WRN: Partial binding information was supplied for an assembly:WRN: Assembly Name: FaceSDK.NET | Domain ID: 3WRN: A partial bind occurs when only part of the assembly display name is provided.WRN: This might result in the binder loading an incorrect assembly.WRN: It is recommended to provide a fully specified textual identity for the assembly,WRN: that consists of the simple name, version, culture, and public key token.WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.LOG: Appbase = file:///D:/Users/ana/Education/My Books\vuru_Service/LOG: Initial PrivatePath = D:\Users\Education\My Books\vuru_Service\binCalling assembly : (Unknown).===LOG: This bind starts in default load context.LOG: Using application configuration file: D:\Users\ana\Education\My Books\vuru_Service\web.configLOG: Using host configuration file: C:\Users\ana\Documents\IISExpress\config\aspnet.configLOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/c17048b1/ac5e9a42/FaceSDK.NET.DLL.LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/c17048b1/ac5e9a42/FaceSDK.NET/FaceSDK.NET.DLL.LOG: Attempting download of new URL file:///D:/Users/ana/Education/My Books/vuru_Service/bin/FaceSDK.NET.DLL.ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
    
    
    Stack Trace: 
    
    [BadImageFormatException: Could not load file or assembly 'FaceSDK.NET' 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 'FaceSDK.NET' 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.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +124   System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +44   System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +187   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +74   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) +82   System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath) +29   System.ServiceModel.HostingManager.GetCompiledCustomString(String normalizedVirtualPath) +164   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +206   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598[ServiceActivationException: The service '/ThahavuruFaceRecognitionService.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'FaceSDK.NET' or one of its dependencies. An attempt was made to load a program with an incorrect format..]   System.Runtime.AsyncResult.End(IAsyncResult result) +495736   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178   System.ServiceModel.Activation.ServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
    

1 个答案:

答案 0 :(得分:0)

虽然看起来还有其他几个错误,但主要问题是硬件功能较弱。我不得不将我的硬件格式从4GB升级到8GB,并且工作正常。