views:

796

answers:

2

I have the following client application and its corresponding config file:

namespace Chapter9
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ExecuteAssembly("AssemblyPrivate.exe");
        }
    }
}

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <codeBase href="file://C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\AssemblyPrivate\bin\Debug\AssemblyPrivate.exe"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

The AssemblyPrivate.exe does not have a public key, nor is it located in the GAC. As far as I know, the runtime should parse the app.config file before looking for an assembly in the client app directory.

The unhandled exception (wrapped for readability) is:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly
'file:///C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\Chapter9\bin\Debug\AssemblyPrivate.exe'
or one of its dependencies. The system cannot find the file specified.

Why it is not working? I need to use dynamic binding (not static).

Kind Regards, PK

A: 

Don't overlook that "or one of its dependencies". Are you sure all AssemblyPrivate.exe's dependencies are available?

Igor Brejc
AssemblyPrivate is just a static void main with Console.WriteLine so - Yes, I am sure.
pkolodziej
Have you tried using the full path as an argument to the ExecuteAssembly method? In the standard Windows form, not as URL?
Igor Brejc
Codebase was introduced not to hardcode any paths.
pkolodziej
I know, but if you want to find out where the problem lies, you have to do a little bit of experimenting... that's always the case with these kinds of things
Igor Brejc
A: 

You probably solved this problem on your own by now, so just for reference:

I believe you are missing an "assemblyIdentity" element. If you specify it additionally to the codeBase element, it should work.

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="office"
                  publicKeyToken="71e9bce111e9429c" />
        <codeBase href="Microsoft.Office.Interop.v11.dll" version="11.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

See http://msdn.microsoft.com/en-us/library/b0yt6ck0%28v=VS.100%29.aspx

Florian Schmitz