10

I have a Web Forms Web Site project. This web site references 4 class library projects. 3 of these class libraries reference a third-party assembly. I am getting the following compiler error for each of the 3 class library projects.

ASPNETCOMPILER : error ASPCONFIG: Could not load file or assembly 'myAssembly' or one of its dependencies. An attempt was made to load a program with an incorrect format. [Project. metaproj]

I have tried all possible combinations of AnyCPU/x86/x64 on the class library projects. I cannot change this on the Web Site project. I have both a x86 and x64 version of the third-party dll. Tried both.

"ClassLibrary.csproj" (default target) (4) -> (ResolveAssemblyReferences target) -> C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1561,5 ): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "ThirdPartyDll, Version=xxx, Culture=neutral, processorArchitectu re=x86", "x86". This mismatch may cause runtime failures. Please consider chang ing the targeted processor architecture of your project through the Configurati on Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture th at matches the targeted processor architecture of your project. [ClassLibrary.cspro j]

The bellow illustrates the solution configuration. Note I cannot change from "AnyCPU" here, only from within each individual class library project.

Solution configuration

All .NET 4

Converting the Web Site to a Web Application is not an option.

Thanks,

Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • See David Sacks answer here: http://stackoverflow.com/questions/10113532/visual-studio-c-c-solution-hitting-mismatch-between-processor-architecture – Tod Thomson Sep 06 '12 at 01:23

2 Answers2

7

Obviously, you have a native 32 bit DLL. So the application pool on IIS must be configured to run the .NET framework in 32 bit mode.

This can be configured in the IIS Manager. Go to "Application Pool", select the relevant application pool and open the "Advanced Settings..." dialog. The 32 bit option is close to the top.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • The same thing occurs with a 64bit version of the third-party dll. I will set the app pool to 32-bit once I am deploying to a dev server. – Sam Leach Jul 27 '12 at 16:13
  • Then it sounds as if the third party library has further dependencies that cannot be found like Microsoft's C runtime DLL. What DLL is it anyway? A private one or an open-source library? – Codo Jul 27 '12 at 16:18
  • dtsearch requires Microsoft Visual C++ 2010 SP1 Redistributable Package to be installed as well as the two main DLLs: dten600.dll and dtSearchNetApi4.dll for 32 bit or dtengine64.dll and dtSearchNetApi4.dll for the 64 bit version. Are they installed? – Codo Jul 27 '12 at 17:10
  • Yes, they are. I work with dtsearch successfully in other projects. – Sam Leach Jul 30 '12 at 09:03
0

One of your referenced assemblies is x86 only and thus the project chain that references it must be build for x86 only. Make also sure that when you deploy your application pool is configured for 32bit.

Ivan Zlatev
  • 13,016
  • 9
  • 41
  • 50
  • I have tried this. Setting all projects to x86. I get Error Could not load file or assembly 'Project' or one of its dependencies. An attempt was made to load a program with an incorrect format. With the x86 third-party dll and everything set to x86. – Sam Leach Jul 27 '12 at 15:33
  • Make sure that you have done that for all solution Configuration. Do a clean. Double-check that you don't have a clashing local version or one in the GAC. Keep in mind that if third party library A is 32bit and project B uses it, then project C uses project B - all three have to be x86 – Ivan Zlatev Jul 27 '12 at 15:41
  • GAC doesn't have a version. What exactly do you mean by a local version? In the bin folder? And by 'all solution Configuration'? See above edit (screen capture of solution 'AnyCPU' option). – Sam Leach Jul 27 '12 at 15:58
  • Clearly all "Any CPU" must be switched to "x86". – Ivan Zlatev Jul 27 '12 at 16:27
  • 1
    There is no option for x86. Only a single option; AnyCPU. – Sam Leach Jul 27 '12 at 16:29