0

I have a WCF project which reference from 2 projects.

  1. A library project (A).
  2. Data Contract Library (B)- A separate project.

This project a reference from FaceSDK.NET third party library. I have used this FaceSDK.NET dll file in another project. But it required to insert in to App.config

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

I want to use the functionality in library project in my WCF project. When I build the project, it build fine. But when it run on the WCF test client, it gives an error as below.

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

Some has suggested that this is due to target platform incompatibility. I have tried to keep it to a single platform. I also tried to add a App.confing file, But no use. Help is greatly appreciated.

In this post, has a similar issue, But this is WCF related.

Edit:

I would add some more information. This project A uses EmguCV wrapper. When I added the OpenCV files (these are 500MB) explicitly to the WCF service's bin it gives the above error. When I removed these files and then put only the project reference the error is bit different.

    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
Community
  • 1
  • 1
diyoda_
  • 5,274
  • 8
  • 57
  • 89
  • I am trying to keep this in 32 bit. it is 32 bit all the dlls and the service itself – diyoda_ Nov 28 '13 at 16:16
  • Can you pin the error to the FaceSDK? Does it work without the SDK without any error (even if the results are not what you want)? Can you use the SDK in a simple Console Application without all the overhead? I think you need to narrow down your problem. – nvoigt Nov 29 '13 at 07:23
  • @Diode and your IIS has Enable 32Bit ticked for this site? – Bob Vale Nov 29 '13 at 09:07
  • @ Bob I changed the application to x64 all the dlls and the projects. I forgot the web service and tried to directly reference the project dll. firstly same memory out of exception appeared, Then I forced the IIS Express to run in x64 using [this](http://stackoverflow.com/a/15491368/892788). Then after a restart suddenly it started working. But I checked on another machine, But the error still exists even I did the same changes to that computer and the code. @ – diyoda_ Nov 29 '13 at 10:09
  • @nvoigt in other machine for web application if FaceSDK.NET.dll is removed the error still exists due to emgucv references.Yes it works fine on an console application. Is it the memory restriction in WCF web services and web applications. I somehow managed to make it work by changing it to x64 and forcing it to run on x64 IIS Express, But not sure what caused it to work because I could not duplicate the fix in another machine – diyoda_ Nov 29 '13 at 10:18
  • See my answer on **[System.BadImageFormatException: Reference assemblies should not be loaded for execution](https://stackoverflow.com/questions/61336306/system-badimageformatexception-reference-assemblies-should-not-be-loaded-for-ex/61702386#61702386)**. – Murat Yıldız May 09 '20 at 19:21

1 Answers1

0

Although there seemed several other errors, Main problem was the less powerful hardware. I had to upgrade my hardware form 4GB to 8GB and it worked fine.

diyoda_
  • 5,274
  • 8
  • 57
  • 89