Welton v3.64
Welton v3.64

Reputation: 2230

Visual Studio 2010 Assembly Reference Issue

I'm using Visual Studio 2010 and C# to build WinForms apps and class libraries. I have some common libraries that I use for all products, and then some product specific libraries for my apps. None of my assemblies are GAC'd. All projects copy their output from their respective bin\Debug folder to a common Repository folder, and all assembly references are pointed to that Repository folder.

For example, Common.DAL.dll, Common.BLL.dll, Product.DAL.dll, Product.BLL, and Product.exe

The references between assemblies are typically something like this:

When all these are included in the same solution, the build depencies are something like this:

Which makes the build order something like this:

  1. Common.DAL
  2. Common.BLL
  3. Product.DAL
  4. Product.BLL
  5. Product.exe

Frequently, when attempting to run an app, I get the following error:

Could not load file or assembly 'Common.DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4e5249f2e70e1da8' or one of its dependencies. The system cannot find the file specified.

I have traced the problem down to the fact that not all of the assemblies built from the solution end up in Product.exe's bin\Debug folder.

If I clean the solution, and then rebuild it, the files appear something like this:

I have checked the properties of all of my projects and properties. They are all using .NET Framework 4. All references to my assemblies have 'Specific Version' property set to false, and 'Copy Local' property set to true.

I can force the missing assemblies to be copied to Product.exe\bin\Debug by adding references to the Common assemblies in the Product.exe project, but since Product.exe doesn't explicitly use the Common assemblies, this feels more like a kludge than a solution.

I've looked through MSDN and Visual Studio documentation to see if I could find out what influences or affects the copying of referenced assemblies, and I've searched SO for similar issues, but I haven't found anything helpful.

I'm at a loss for where to go or what to do next.

Upvotes: 2

Views: 2234

Answers (2)

McKay
McKay

Reputation: 12624

In your question you say:

I can force the missing assemblies to be copied to Product.exe\bin\Debug by adding references to the Common assemblies in the Product.exe project, but since Product.exe doesn't explicitly use the Common assemblies, this feels more like a kludge than a solution.

I don't think I concur. It's not perfect, but Visual Studio sometimes requires this even intra-solution. It depends on how you are using the class.

While you may think it is a little kludge, it seems like your other (dare I say "kludgy") requirements (one project per solution) make things seem kludgy

Upvotes: 3

Henk Holterman
Henk Holterman

Reputation: 273631

You should only reference bare assemblies when they are relatively stable and outside of the Solution.

Inside your Solution, reference them from the Projects tab. This will make VS configure the correct dependencies and build-order between projects.

In your current setup, verify the Project dependencies (Solution|Properties).

Upvotes: 2

Related Questions