3

I write a WCF Service Library hosted under an IIS website to server requests from other websites. The service has a method named Encode, is to perform encoding video files that are uploaded by end-users. I use the following assemblies:

Microsoft.Expression.Encoder.Api2.dll, Microsoft.Expression.Encoder.dll, Microsoft.Expression.Encoder.Types.dll, Microsoft.Expression.Encoder.Utilities.dll,

I have tested the encode function directly from console application. However, when I test via IIS website, the error bellow always throws whenever I call the encode method.

{"Could not load file or assembly 'Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format."}

I checked whether those Dlls are in Assembly folder, and they are not, so I copied them to GAC, and they are in GAC32. I had to do so because when I published WCF to IIS website, it copied those Dlls to bin folder and I could not add service reference. I could only add service reference when I delete those Dlls from bin folder. Copy those Dlls to GAC.

I also read some articles that indicate there is a conflict between the DLL platform and running application's platform. That means that DLL is built with 32-bit application, but the running application is running under 64-bit application, etc. I then tried to set the platform and framework to 32 and 4.0 accordingly, but the running application will throw the errors when I add service reference.

I'm confused and do not know where is the root of the problem and how to resolve it.

Update: This is my application pool: enter image description here

NPovlsen
  • 337
  • 1
  • 16
hoanvd1210
  • 149
  • 5
  • 15

2 Answers2

2

"An attempt was made to load a program with an incorrect format", this part is giving you the key, this happens when you try to use an x64 assembly in a 32 bit process, thus, your IIS is set up as 32 bits (is as it comes by default), use the 32 bit dll's or change your IIS config to run in 64 bit mode

Gusman
  • 14,905
  • 2
  • 34
  • 50
  • Exactly error when I host wcf under IIS website is: The system cannot find the file specified. Could not load file or assembly 'Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. – hoanvd1210 Aug 29 '15 at 06:29
  • If it can't find a file the easiest way to make it available is to copy it to the bin folder of your website. If you copy it and then still complains about missing file/dependency then those dll's need more dll's which you should also copy – Gusman Aug 29 '15 at 06:31
  • Also, a good idea, instead of only copying those dll's just install the full encoder pack to the server from here: http://www.microsoft.com/en-us/download/details.aspx?id=24601 – Gusman Aug 29 '15 at 06:32
  • as I said before, when I copy those DLLs to bin folder, It wills throws errors and cannot call the service. – hoanvd1210 Aug 29 '15 at 06:33
  • what error gives when you try to add the reference? – Gusman Aug 29 '15 at 06:34
  • I have installed Encoder Expression on local machine and I can perform encoding using those dlls via console application. I'm trying to install the package you sent. – hoanvd1210 Aug 29 '15 at 06:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88248/discussion-between-hoanvd1210-and-gusman). – hoanvd1210 Aug 29 '15 at 06:42
  • +1 I encountered this issue doing screen recording with Microsoft.Expression.Encoder for automation tests. Resolved it by running the test runner (NUnit 3) in x86 mode. – dotnetesse Jul 06 '17 at 16:04
2

By now you probably have already figured out the solution to the this problem. Your Application pool can not load 32bit dlls into it because it is running as a 64 bit process. To resolve this switch your application pool to run as a 32 bit process. After you change this value run an issreset to make sure the value takes hold.

enter image description here

Stuart Smith
  • 1,931
  • 15
  • 26