locked
Error: Unable to load DLL

    Question

  • I'm using VB 2008 express. I need to use shape files in my project, and I'm using a couple DLLs to get that functionality. There is an older DLL called "shapelib.dll" that can do what I need, but is old enough that VB won't allow me to use it as a reference. So someone wrote a .Net wrapper for it (MapTools.dll) which I can reference. On my development machine, I put both maptools and shapelib in the same folder as my app, reference maptools, and when it needs to do something, it can access shapelib. This all works great on my development machine.

    On a different machine, I get the error message "Unable to load DLL 'shapelib.dll": The specified module could not be found.

    The file is in the same folder as the program and the Maptools dll. I have tried moving shapelib.dll into C:\Windows and C:\Windows\System32, but nothing will make it happy.

    Back on my development machine, if I remove shapelib from my /bin/Release folder, I get the exact same error when running the app. However, if I put the shapelib dll in that folder, the app will run fine. On the other computer, it still doesn't think the file is there.

    Ideas?
    Monday, December 01, 2008 2:18 AM

Answers

  • From what I was able to determine the MapTools wrapper was written in C#. I converted the project to VB but can't post it here. I would suspect that you could probably just add this code to your project. If anyone is interested in the ported project let me know where to send it or upload it.

     

    The assembly had been strong named, perhaps so it could be registered in the GAC (the key file is in the zip file), but I don't really see anything particularily special about the wrapper.

     

    Thursday, December 04, 2008 2:04 PM

All replies

  • Hi,

     

    Well, If you mean :

     

    You have moved the Dlls ( shapelib.dll, MapTools.dll ) to a special directory < such as ( for example ) \Libraries\ > and then added them to your application references, so let me tell you < It won't work >,

     

    Because if your application on ( The Logical Driver E:\ ) E:\MyApplication.exe >> 1 of the Libraries = E:\Libraries\shapelib.dll ,

    the path won't change when you move the files from ( Driver To Driver ) or from ( Folder To Folder ),

     

    Mean :> If we move the application from the current directory ( E:\MyApplication.exe ) To ( D:\MyApplication.exe ) the Libraries DirectoryPath will be as follows ( E:\Libraries\ ) <> so nothing has been changed,

     

    to fix that problem you should ( Double Click On ( My Project ) from the TabControl ) select * References * Mark the wanted libraries ( References ) and from the Properties Explorer ( Right to the TabControl ) set the Property ( Copy Local ) to ( True )

     

    now the files are going to be copied to the same directory of your application, and will run from it .

     

    Best Regards,

     

    BVS.

    Monday, December 01, 2008 3:19 AM
  • MapTools.dll is listed in the references, and Copy Local is set to True for that one.

    Shapelib.dll is an older DLL so I cannot add it to the references list. I manually copy this file into the same folder as the application and maptools.dll. On the development machine, this works fine. On another machine it doesn't.
    Monday, December 01, 2008 3:30 AM
  • Hi Again,

     

    I'm sorry, I don't have that library to make a test but tried other vb6 libraries and worked fine,

    If Shapelib.dll isn't listed in your application references >> try copying it to the original path ( WindowsDriver:\Windows\System32\Shapelib.dll ) of the other machines,

     

     

    Best Regards,

     

    BVS.

     

    Monday, December 01, 2008 3:52 AM
  • When I try to add shapelib.dll to the references, I get the following error: A reference to '..../shapelib.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

    The other DLL was written specifically because of this. It's nothing but a wrapper for the shapelib dll.

    On the machine where I got the original error, I've tried putting it in \Windows\System32 and in \Windows. In both cases, nothing changed. It still said it couldn't find the file.

    Do you want a copy of the dlls?
    Monday, December 01, 2008 4:12 AM
  • Hi Again,

     

    yeah please <> If you don't mind ... >> e-mail on my profile ,

    Monday, December 01, 2008 4:33 AM
  • Hi Mx270a,

    I would recommend that you use the Reflector to see how the wrapper library to reference the
    shapelib.dll. Let us know how you get these libraries to know the more information about your issue. Also I need to know how you deploy the application to the client computer. If you just use X-copy to copy the whole folder which contains the executable file and the additional files to the user computer, what happens.

    Riquel
    Tuesday, December 02, 2008 6:58 AM
    Moderator
  • Does shapelib.dll have any dependencies? Sometimes dll libraries use other libraries or files and maybe you're missing one or more of them. That particular unmanaged code library should load as long as it's somewhere in the Windows search path.

     

    Otherwise, I would say it's a security issue. You may want to try changing the trust level of the application to high or full.

    Tuesday, December 02, 2008 2:07 PM
  • Actually, I have the source code for each of the DLLs. I'm not familiar with building DLLs, but I don't see anything in shapelib that looks like a dependancy.

    I normally deploy the application with an INNO setup program, but I have also tried just copying the file over. In both cases, I get the error message.

    The link for changing trust levels applies to .Net v1 which I don't have. (I'm using 2.0). The option in Administrative Tools doesn't exist on my machine, so I can't change anything that way. I looked for a newer way to do the same thing on .Net 2.0, but all I saw was how to set trust levels in asp.net.
    Tuesday, December 02, 2008 3:54 PM
  • If the 2.0 Framework is installed then there should be a .NET Framework 2.0 Configuration utility under Administrative Tools in Control Panel.
    Tuesday, December 02, 2008 5:25 PM
  • Looks like the .Net config utility is included in the SDK, but not the runtime. I'll install the SDK on my test machine and see what happens when I change the security then.
    Tuesday, December 02, 2008 7:10 PM
  • I have been having the identical problem with ShapeLib.dll for over a year, but shelved it with a workaround, but now have to solve it as the old server is dead. This also applies to another external DLL my Website uses, AgDisp.dll, and I do not believe it is related to the DLLs themselves, but rather to locating and accessing them as external non-.NET dlls.

    What I have established long ago and this week that running the website from with Visual Studio (both 2005 and now 2008) the application runs fine, locating and using the DLLs correctly. it also works fine on a website installed on a PC or laptop wher I have adminsitrator rights. However, I have bene unable to get a website to work on a server wher I am not administrator. My eventual work around (after a very long time of getting nowhere), as this was just a reasearch and not commerical app, was to take an image of my development PC and put it on the PC used as webserver, and then I can install and run the website, accessing these two external DLLs correctly. I some time ago spent a lot of time looking on Internet and found many people with same problem accessing external DLLs (not ShapeLib) but no solutions that worked. I have tried setting paths making sure the DLLs are accessible. (they are in the bin directory of the website, together with all the other dlls), but that doesn't work.  Have also given user ASPNET and IIS_WPG full rights to the bin directory and that doesn't work. I have also explicitly added these dlls to the projects using them and set the Copy to Output to C
    opy Always, and also tried setting Build action to Embedded Resource. For instance I do not understand that when building and publishing the website these 2 DLLs are automatically copied and located with the other DLLs, but the app can't find them when it runs. (And it didn't need the Copy Always to copy them - they have always been copied to the website bin directory.)

    I have used DEPENDS to establish that AgDisp.dll needs Kernel32.dll and NTDLL.dll, and ShapeLib.dll needs these 2 and also MSCOREE.dll, MSVCR71.dll, all of which are on the server in the path.

    As I said, I am sure it is a problem relating to these DLLs being external and not .NET. and nothing to do with them being ShapeLib.dll or AgDisp.dll - very many other poeple seem to have the identical problem with other external DLLs. Running from within VS they are located and used, but not on an external published website.

    So please, can anyone tell us how to solve this problem?

    Thanks

    Wednesday, December 03, 2008 1:19 AM
  • Can it be that this is one of the times when you need to run the Regsvr32 tool (Regsvr32.exe) ?

     

    http://support.microsoft.com/default.aspx/kb/249873

    Wednesday, December 03, 2008 2:39 AM
  •  bdbodger wrote:

    Can it be that this is one of the times when you need to run the Regsvr32 tool (Regsvr32.exe) ?

     

    It's a standard Windows DLL and not a COM DLL.

    Wednesday, December 03, 2008 3:09 AM
  •  postea wrote:

    As I said, I am sure it is a problem relating to these DLLs being external and not .NET. and nothing to do with them being ShapeLib.dll or AgDisp.dll - very many other poeple seem to have the identical problem with other external DLLs. Running from within VS they are located and used, but not on an external published website.

     

    You have to remember that the IDE runs in a different security context than an ASP.NET application and will typically have Administrator privileges. I would take a look at the suggestion I made to the other OP with respect to application trust level.

    Wednesday, December 03, 2008 3:15 AM
  • After I installed the SDK on the test box, I had the .Net Configuration program. It wouldn't let me adjust the trust level of my program because it didn't have a hash. That means it needs a Strong Name key file. So I told it to sign the assembly, and then it wanted me to do the same for the MapTools.dll. So I rebuilt that one too with a signed assembly. Added the updated version of it into the main program, built it, and copied both new files to my test machine. I used the .Net config utility to give both the program and MapTools.dll full trust. However, I still get the same message about not being able to find shapefil.dll.


    Alternatively, what does it take to convert an older DLL to be .Net compatible? I have the source code which I upgraded into VB C# Express.
    Wednesday, December 03, 2008 7:49 PM
  • If you have the source code can you port it to Visual C++ 2008 (.NET)?

    Wednesday, December 03, 2008 11:51 PM
  • Hi Mx270a,

    Please post the source code of
    a wrapper for the shapelib.dll in this scenario. Let us see how the wrapper library uses the unmanaged library to find some methods here.

    Riquel
    Thursday, December 04, 2008 6:24 AM
    Moderator
  • I tried the software on a different computer and was able to run it just fine. No SDK, no setting of trust levels, nothing. Just click and run. Seems I might have an issue specific to the machine I had been testing on. I'll wipe/reload it and see what happens then.

    Here are zip files of the two DLLs, if anyone wants to take a peek at them. I still have an interest in getting shapelib to be directly supported in .Net instead of needing the MapTools wrapper.

    http://lefebure.com/files/MapTools.zip
    http://lefebure.com/files/shapelib.zip
    Thursday, December 04, 2008 6:48 AM
  • From what I was able to determine the MapTools wrapper was written in C#. I converted the project to VB but can't post it here. I would suspect that you could probably just add this code to your project. If anyone is interested in the ported project let me know where to send it or upload it.

     

    The assembly had been strong named, perhaps so it could be registered in the GAC (the key file is in the zip file), but I don't really see anything particularily special about the wrapper.

     

    Thursday, December 04, 2008 2:04 PM
  • I'm interested.

    Thanks,
    Lance
    Thursday, December 04, 2008 5:15 PM
  • Lance, the project is on its way to you.

     

    Thursday, December 04, 2008 5:44 PM
  • Paul, the VB project you sent back to me was excellent. I did a little clean up of the comments, and copied it into a new class in my main application. It runs great. This has completely eliminated the need for the MapTools wrapper. Thanks.
    Friday, December 05, 2008 3:37 AM
  • Paul,
        I'm interested in teh VB.NET port if you are still sending it out.

    Thanks, Will.
    Friday, January 16, 2009 5:55 PM
  • I would like to get a copy of the shapelib project converted to VB. Please send it to c5.2008.survey_at_gmail.com

    Thanks!
    Wednesday, February 04, 2009 7:06 PM
  • Hi Paul

    Could you send the VB port to me too?

    Thanks
    Wednesday, February 18, 2009 8:10 AM
  • I would love to get my hands on the VB port as well.
    Tuesday, March 17, 2009 4:02 AM
  • Seems I'm not the only one interested in shapefile support in VB.Net. The following link is a zip file containing the code discussed earlier in this tread.

    http://lefebure.com/software/shapefiledll/

    There is an example project showing how to use the dll from within VB to read the points of a ring. I only read and write ring objects, so I can't help with much else, although the wrapper will show you what variables need to be passed to the functions for accessing other types of objects.

    -Lance


    • Edited by mx270a Friday, November 18, 2011 3:40 PM Fixed URL
    Friday, April 17, 2009 2:50 AM
  • The link above is dead.  If anyone has the link or the code I would appreciate it if they would post it or send  me a copy.

    email hatch_1989[at]yahoo{dot}com

    Friday, September 16, 2011 7:02 PM