Hi,
at the moment we have very strange problems with assembly directories:
Following is the main structure of our project:
- An ActiveX-control in "d:\TheProject\bin\debug" which is developed
by us. It opens an assembly in the same directory (lets call it
MainAssembly). That assembly contains a control which is then
displayed in the ActiveX-control
- Some app under "c:\Program Files", which loads an ActiveX and
displays it. Note that there may be different apps from different
vendors - it's an industry standard specification (FDT) which you can
compare to a plugin system based on COM. FDT applications scan the
registry for a COM components that are registered under a specific COM
category. The found components are then hosted. Our ActiveX is such a
component.
The COM-stuff works as expected. Our problem is this:
in the assembly we use Microsoft CAB. All three assemblies
Microsoft.Practices.CompositeUI.dll,
Microsoft.Practices.CompositeUI.WinForms.dll and
Microsoft.Practices.ObjectBuilder.dll are in our directory "d:
\TheProject\bin\debug"
This code example from our MainAssembly doesn't work:
private void CrashTest()
{
try
{
Test1();
Test2();
Test3(); // =throws an exception!
}
catch (Exception err)
{
}
}
private void Test1()
{
Type t = typeof (WorkItem); // Class in
Microsoft.Practices.CompositeUI.dll
}
private void Test2()
{
Type t = typeof(Builder); // Class in
Microsoft.Practices.ObjectBuilder.dll
}
private void Test3()
{
Type t = typeof(DeckWorkspace); // Class in
Microsoft.Practices.CompositeUI.WinForms.dll
}
I put a breakpoint into Test3() but that one won't be hit. Instead a
FileNotFoundException will be thrown when I try to step into this
function. The message is this:
"The file or assembly Microsoft.Practices.CompositeUI,
Version=1.0.51205.0, Culture=neutral, PublicKeyToken=4ca05d3ac5586cd9
or a dependency of it wasn't found. The system cannot find the
specified file."
But this is really strange, because in Test1() exactly this assembly
is loaded. I also checked this manually by examining
typeof(WorkItem).Assembly.Location.
Next I added an event handler to the AppDomain's AssemblyResolve-
event: it was fired with args.Name =
"Microsoft.Practices.CompositeUI.dll". When I return
typeof(WorkItem).Assembly, it works.
Has anybody a reasonable explanation for this behaviour? I think it
may be associated somehow with the main application because it is in a
different directory. When I use a small test application in the d:
\TheProject\bin\debug-directory, everything works fine. Btw isn't it
strange that the MainAssembly can be called? I thought that assemblies
can only be called when they're in the same directory as the
application, in a subdirectory, in the GAC or if the .config-file of
the application specifies the assembly's directory.
I have absolutely no clue what's going on here and each hint is more
than welcome,
mfg Steven