Now that I did try it out myself, I think I found the reason for your problem:
you get fooled by Visual Studio.
Visual Studio usually deploys (silently) all the project references to the build output folder of the given C# project. I.e. when you add in the main program project a reference to the LibA and LibB, then they get deployed beside the main program in the bin\Debug or bin\Release folder.
If you do not reference these two libs, you get only the main program assembly deployed to its bin\Debug or bin\Release folder.
What you observe is that the type from LibA can not be constructed since the types could not be found by .NET assembly resolution machinery.
Do the following:
1) set the output folder of all projects to ..\bin (instead of bin\Debug or bin\Release)
2) recompile the solution.
Now, all assemblies are in the same bin folder and .NET can resolve the needed types.
Cheers
Andi
PS: Example code:
Main Project, no references to neither LibA nor LibB.
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Type type = Type.GetType("LibA.ClassA, LibA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
object obj = Activator.CreateInstance(type);
Console.WriteLine(obj.ToString());
}
}
}
LibA with reference to LibB:
namespace LibA
{
public class ClassA
{
public ClassB Other { get; set; }
public ClassA()
{
Other = new ClassB();
}
}
}
LibB:
namespace LibB
{
public class ClassB
{
public void Write(string message)
{
Console.WriteLine("Message: {0}", message);
}
}
}
Now, the important part is: build all projects such that the resulting assemblies are located in *one* directory.
This can be done by one of the following:
- the steps as described above
- copy the assemblies manually to one directory (crude)
- if you have a specific deployment structure in the product, implement an assembly resolution handler
I suggest to go the 1st approach since it is the simplest one. Otherwise, a resolution handler would help.