Mark Fruhling
Mark Fruhling

Reputation: 606

Is there a difference when referencing dll binaries or referencing a project in Visual Studio 2008?

I have two projects. Project A is a web project and project B is a Data Access Library. Project B has references to another Project (Project C), as well as some third party dlls that are referenced through files in a directory call "Library". If I reference Project B as a project reference, everything works. If, instead I reference the dlls that are output into the bin/debug folder of Project B, everything builds, but I get the following error we the built in development web server tries to show the default page.

[BadImageFormatException: Could not load file or assembly 'my_dal.data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.]

I'm running Windows 7 64 bit Operating System, so it would seem I have a 32/64 bit problem, but I can't see how the build process is working with one reference and not the other.

Upvotes: 3

Views: 2891

Answers (3)

Chandra Sekaran V
Chandra Sekaran V

Reputation: 182

The reason behind why referencing the files in bin/debug folder fails is because those files gets wiped out when you rebuild/clean the solution. The best way to reference a project in another project is to add it as a project reference and not through binary files.

Upvotes: 2

iamkrillin
iamkrillin

Reputation: 6876

The error you are getting there indicates you are trying to either
A) Load an assembly built for 64 bit and your on 32 bit
B) Load an assembly built for 32 bit and your on 64 bit

You can fix this error by changing your project to build for "Any CPU"

Upvotes: 0

Tejs
Tejs

Reputation: 41236

That's because the project knows about it's own dependencies. A DLL doesnt provide information on dependent binaries that visual studio also needs to provide.

Either way, you should reference your project as a project not a binary, because then when you make changes to it, they automatically update the DLL on build.

Upvotes: 2

Related Questions