Problems with assembly references  
Author Message

PostPosted: Visual C# General, Problems with assembly references Top


I am developing a windows service application which refers to the class library A and this class library A refers to my windows service application. I need both references in order to use particular classes. Well there's nothing wrong, except the warning messages I'll get when building the application in VS 2005.

ViestienAjastusSovellus.exe (Windows Service) => VAS_RemoteModuuli.dll (Class library)

VAS_RemoteModuuli.dll => ViestienAjastusSovellus.exe

Here are the warning messages I'll get from VS 2005:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning MSB3112: Two or more assemblies have the same identity 'ViestienAjastusSovellus, Version=, Culture=neutral, ProcessorArchitecture=msil'.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning MSB3181: Two or more files have the same target path 'bin\Debug\ViestienAjastusSovellus.exe'.

ViestienAjastusSovellus -> C:\Documents and Settings\Juha\My Documents\Visual Studio 2005\Projects\ViestienAjastusSovellus\ViestienAjastusSovellus\bin\Debug\ViestienAjastusSovellus.exe

Can somebody tell me are these warning messages important and if not, is there a way to avoid getting them in VS 2005



Visual C#11  

PostPosted: Visual C# General, Problems with assembly references Top

Yes they are important. You are creating assemblies with the same name which means they will collide. You need to make sure that each assembly has a unique name. Note that the file extension is not part of the name. Therefore the following two assemblies have the same name even though they are different files:


You need to rename one of them.

As for the cyclic referencing you don't want to do that either. I'm surprised it even works. Normally the tools are smart enough to figure out the dependencies (in this case) and complain but they can't catch all cases. In general in order to compile assembly A all its referenced assemblies must be available. Now assume that assembly A depends on assembly B. Additionally B depends on A. You add a new class to assembly B and want to use it in assembly A. Conversely you add a new class C in assembly A that depends on B. The compiler is in a situation where it needs to compile B in order to pick up the new class to use in A but A requires B before it can be compiled. In the "best" case it'll reuse the version from a previous build. In the worst case it'll fail. This is bad.

To share classes in multiple assemblies and avoid the dependency issue create a third assembly and store the common files there. Thus the common files used in your class library and the service would be moved to a third assembly. This breaks the circular dependency issues. However in your case you could just move the common files to the class library since the dependency would be from the service to the class library.

Michael Taylor - 11/30/06


PostPosted: Visual C# General, Problems with assembly references Top

Big thanks!

I got it working now when I moved common files to a class library and after that I didn't get those warning messages anymore.