dll not found when changing the path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tincho87
    New Member
    • Nov 2009
    • 8

    dll not found when changing the path

    Hi everyone, sorry about my english. Im having a problem and i don't know how to fix it.

    I have a plugin-based application that i'm developing. Every plugin has a reference to a dll that has different static classes with functions. When i run the application with all the dlls (plugins and their references) in the same directory, the application works fine. But the problem comes when i change the application's path, leaving the dlls in other path. When i run the application, the plugin dll thrown an exception saying that the "functions dll" could not be found, but the dll is in the same directory as the plugin :| .

    If i don't explain well:
    C:\app.exe
    C:\plugin.dll
    C:\functions.dl l
    It works fine.

    C:\test\app.exe
    C:\plugin.dll
    C:\functions.dl l
    It doesn't work.

    I don't know where is the problem.
    I'll be really grateful for your help.

    Thanks
    Greetings
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Well, it depends on the code you have to load your plugins. However, I'm betting it's just looking in the working directory (ie, LoadPlugin("plu gin.dll") or some such thing.

    That's why it's not finding the plugins... it's likely looking in the same directory app.exe is running out of, so when you change that it won't find them. I bet if you moved your two plugin dlls into the c:\test folder, it would work again.

    You've got a couple of options (that I can think of)...

    1) Keep your plugins in the same directory as your application. This is fine as long as you keep your plugins with your application (though you may want to put them in a plugins folder (ie, ".\plugins\plug in.dll" and ".\plugins\func tions.dll")

    2) Hard code your plugins folder. Instead of loading by the plugin name, fully qualify it (ie, "c:\plugin. dll" and "c:\functions.d ll"). I wouldn't recommend this since it's pretty restrictive. You may want to deploy your app on other computers and users may not want things to always go in the same folder.

    3) Allow your app to configure the path to the plugins folder. This is especially good if you want your plugins to be loaded from any arbitrary location.

    Of the three, the third is probably the "best" solution as it gives you the most freedom; however, the first is also perfectly acceptable. I've written a plugin system myself and I actually used the first solution (though I had my plugins in a subfolder off my working directory) that involved relative file links.

    Hopefully one of those helps you, or at least helps you think of a better way of doing it. Good luck!

    Comment

    • tincho87
      New Member
      • Nov 2009
      • 8

      #3
      Hi, thanks a lot for your reply, but the problem is not the application, its in the plugin, because when i put the application in the plugin directory, it works fine, but when i put the application in another directory, it founds the plugin, but the plugin doesn't "see" the functions dll =S. i think its like the plugin uses the application "startup path" to "search for the references"(fun ctions dll), and when the plugin and the application are in the same directory, it works fine, but when i move the application to another path, the plugin searchs for the references in the application's new path. i don't have idea what could be.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Oh I see, plugin.dll needs to find function.dll?

        Again, I don't really have your code, but does plugin.dll look for function.dll by just asking for the directory? If so, that would be the problem, since the working directory is for app.exe. You'll need to direct plugin.dll to look for function.dll in the same directory plugin.dll was found in. App.exe should be able to tell you where it found plugin.dll.

        Sorry for the confusion.

        Comment

        • tincho87
          New Member
          • Nov 2009
          • 8

          #5
          The plugin is a "class proyect library" that references to the "functions dll". is there anyway to "tell" the plugin that the "functions dll" is "there with him"?

          i've tried to set the current directory in the app, but it still happening =S

          thanks

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Is plugin.dll a project that you built, then included functions.dll as a reference?

            Comment

            • tincho87
              New Member
              • Nov 2009
              • 8

              #7
              exactly :) the plugin.dll is a "class proyect library" that has a reference to "functions. dll"

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Hi tincho87,

                Do you have control over the plugin.dll code?
                Could you take a look at how it is referencing the functions.dll?

                Comment

                • tincho87
                  New Member
                  • Nov 2009
                  • 8

                  #9
                  hi, the plugin is loaded in the app by the System.Reflecti on, i mean, its not referenced. But the "plugin proyect" has referenced the "functions.dll" (References->Add reference. Then, i select the "functions. dll" and import their functions by the "using namespace")

                  Comment

                  • GaryTexmo
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1501

                    #10
                    Originally posted by tincho87
                    exactly :) the plugin.dll is a "class proyect library" that has a reference to "functions. dll"
                    Hmm, interesting.

                    I don't suppose it would be possible for you to register functions.dll with the GAC, would it? Then plugin.dll could load it from there instead of a file in a folder...

                    This particular issue has never come up for me, but I guess I would have assumed things were smart enough to figure out how to load references for themselves.

                    So yea, give the GAC a try... here's a link I found with google on how to do this.
                    Hi Friends, I have created an DLL & how do I register that DLL into GAC so that all my applns in my machine. Regards, Vipul Mehta

                    Comment

                    • tincho87
                      New Member
                      • Nov 2009
                      • 8

                      #11
                      hi, i discovered something strange: when i put the "functions dll" in the same path of the app, it works!. i think that the plugin is searching for the reference in the path of the app...but why?

                      C:\app.exe
                      C:\plugin.dll
                      C:\functions.dl l
                      It works fine.

                      C:\test\app.exe
                      C:\plugin.dll
                      C:\functions.dl l
                      It doesn't work.
                      C:\test\app.exe
                      C:\plugin.dll
                      C:\test\functio ns.dll
                      It works too.

                      Comment

                      • tincho87
                        New Member
                        • Nov 2009
                        • 8

                        #12
                        Hi, this image could help.

                        Comment

                        • tincho87
                          New Member
                          • Nov 2009
                          • 8

                          #13
                          Hi everyone. I found the solution!
                          I used the app.config to add a private path, and its now working!! :)

                          Thanks

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #14
                            I'm really happy that you found a solution!


                            Congrats :)

                            -Frinny

                            Comment

                            Working...