1

I am pretty new to working with class libraries and was hoping someone could tell me if I'm missing something or if what I'm trying to do is even worth it:

I have a dll that is being run from a VB6 application. We'll call it test.dll. Test.dll uses another .dll, that we'll call Dep.dll.

At first, I just added the reference to Dep.dll in Test.dll and set Copy Local = 'False'. Then I set the assembly binding in the VB6 application config file:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
        <assemblyIdentity name="Dep Name"
                          publicKeyToken="xxxxxxxxxxx"
                          culture="neutral" />
        <codeBase version="1.0.0.2"
                  href="file:\\dir_name\dep.dll"/>
    <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.0.2"/>
      </dependentAssembly>
    </assemblyBinding>
</runtime>

But I hear that I could have created a app.config file for Test.dll and had the aforementioned entry in there instead of in the app config file for the VB6.exe.

For some reason, I couldn't get the reference to work this way. Here is the error message:

Could not load file or assembly 'Dep.dll, Version=1.0.0.2,Culture=neutral,PublicKeyToken=xxxxxxxxxxx' or one of its dependencies. The system cannot find the file specified.

I changed the Build Action property to the app.config file to 'Content' and Copy Output property to 'Copy Always'. I also didn't do anything to the original reference to Dep.dll in Test.dll's project file. I removed the assembly binding entry for Dep.dll from the VB6.exe's app.config file.

We have a single working example here of a dll using an app.config file, however it doesn't bind assemblies, just has a bunch of app settings.

The research I'm doing is suggesting that maybe what I'm doing isn't possible or even best practice, but now I'd just like to know whether what I'm trying is possible. If so, what am i missing?

  • No, a DLL cannot have a .config file. Use Fuslogvw.exe to troubleshoot assembly resolution problems. – Hans Passant Jul 10 '14 at 19:09
  • @HansPassant -- It can (the dll example that my colleague showed me is definitely using the app setting and connection settings from an app config file), but I'm doing some additional searches and I think that my problem might be that the vb6 applications that my dll is being called from have app.config files of their own? this is where i'm getting my hypothesis from: [http://stackoverflow.com/questions/3255820/apply-an-app-config-to-my-dll-assembly?rq=1] – user3137512 Jul 10 '14 at 19:21

1 Answers1

0

The concept of assemblies is foreign to VB6, and VB6 DLL's are an entirely different animal from .Net DLL's (VB6 compiles to native code, .Net compiles to IDL). Also, a VB6 EXE doesn't use app.config to read configuration information (unless you "roll your own" xml reader). It uses .ini files or the registry.

Now, you haven't specified which type of DLL Test.Dll and Dep.Dll are, and without this information any answer involves some guesswork. However, if you're trying to look up assembly information about a DLL in an app.config file using VB6, it's not going to work. VB6 DLL's have no idea what assembly binding is.

Your VB6 EXE uses COM architecture to access DLL functionality. If you want to expose the .Net architecture to VB6, you use .Net Interop services. [This article])http://support.microsoft.com/kb/817248) explains how to call .Net assemblies from VB6. If you want to make use of app.config stuff, then create a .Net class that exposes its interface via Interop, and has methods that get configuration information from app.config. Then the VB6 exe can call those methods. This article looks like a pretty good summary of how to do this.

BobRodes
  • 5,990
  • 2
  • 24
  • 26