Re: Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies....

3,090 views
Skip to first unread message
Message has been deleted

Matt

unread,
Jun 26, 2015, 8:05:41 PM6/26/15
to open...@googlegroups.com, calum.fletc...@gmail.com
Are all the other DLLs in the same directory?

On Friday, June 26, 2015 at 7:12:56 AM UTC-4, Calum Fletcher wrote:
Hi,

I am trying to integrate the C# .NET binding of the ALPR into a project I am working on. I have downloaded the pre-compiled DLL (64 bit) and added it as a reference into my C# project. Everything seems to compile OK, but when I run my application up I get the following:

Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies. The specified module could not be found.

Interestingly, if I run the DLL through DependencyWalker, I get the following error appear straight away:













The dependency walker log states:

Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

I have also tried to integrate the 32 bit version and I get the same error when I try to run up the application but the dependency walker error does NOT appear with that version.

If anyone could help with this, it would be most appreciated. My application is running .NET 4.5, if this helps at all.

Thanks

Steven Eaton

unread,
Jun 27, 2015, 1:44:08 PM6/27/15
to open...@googlegroups.com
You can also get that if it can not find the conf file, or the runtime data directory.   When in doubt I dump all the dlls in my output directory, link that dependency, and I put the conf and runtime data in a specific spot and hard code them.  Once things are working then ya can get cute

Calum Fletcher

unread,
Jun 29, 2015, 10:09:06 AM6/29/15
to open...@googlegroups.com
Yes, all the other DLL's were contained in the same directory. I have just tried copying all the OpenALPR files to my bin folder as well then referenced that DLL but I get the same thing again. Really starting to get annoying now :( - I also don't understand what you mean by put the conf and runtime in a specific spot and "hard-code" them..? As far as I was aware was I should just be able to reference the .NET DLL and away I go? Thanks

curtis...@verizon.net

unread,
Jun 29, 2015, 10:35:26 AM6/29/15
to open...@googlegroups.com
Wow...  I'm trying to get this to work, too - 32 bit in my case.  I add the dll as a reference just fine - it appears in the list.  But I get an error in the "using openalprnet;" - are you missing a using directive or assembly...  Yet the intellisense is just fine with it.  Frustrating...


Curtis DeHaven

unread,
Jun 30, 2015, 9:12:00 AM6/30/15
to open...@googlegroups.com
I got past my problem - the project was built against 2.0.  Changed that to 4.0 and I can at least compile.  I too got the specified module could not be found...  I ended up copying all of the dlls (14 of them) into my bin\debug folder and got past that.  Now I'm getting an exception where it's accessing protected memory.  Here's my code...

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using openalprnet;

namespace ConsoleApplication26

{

  class Program

  {

     static void Main(string[] args)

     {

       string country = "us";

       string configFile = "C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\openalpr_32\\runtime_data\\config\\us.conf";

       string runtimeDir = "C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\ConsoleApplication26\\ConsoleApplication26\\bin\\Debug";

       AlprNet alpr = new AlprNet(country, configFile, runtimeDir);

       AlprResultsNet result = alpr.recognize("C:\\xxxx\\cdehaven\\Documents\\Visual Studio 2013\\Projects\\openalpr_32\\samples\\us-2.jpg");

     }

   }

}


Now mind you, I don't know if I'm even using openalpr right or not!  Just getting further along than I did yesterday...
Hope this helps.
Curt

Calum Fletcher

unread,
Jun 30, 2015, 10:19:47 AM6/30/15
to open...@googlegroups.com
Ah interesting. I'm guessing that's what Steven meant when he said 'hard-code' the config and runtime data. I'll give this a go shortly! I still don't really think copying the DLL's to the debug folder is a solution though, as what happens when it moves to production or rebuild etc..would we have to do the same?

Anyway...one step at a time I guess. Thanks for your help Curtis, glad your getting somewhere!

Oh, by the way in terms of the alpr usage, there is a sample project if you fork the master from Github it is located in src/bindings/csharp. I managed to get the code I needed from that..I just couldn't get the DLL running so hopefully I will be able to piece it together now...

Matt

unread,
Jun 30, 2015, 7:02:37 PM6/30/15
to open...@googlegroups.com, calum.fletc...@gmail.com

    string configFile = "C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\openalpr_32\\runtime_data\\config\\us.conf";

       string runtimeDir = "C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\ConsoleApplication26\\ConsoleApplication26\\bin\\Debug";

The config file should point to openalpr.conf and the runtimeDir should point to C:\\Users\\xxxx\\Documents\\Visual Studio 2013\\Projects\\openalpr_32\\runtime_data\

I have a feeling those values being incorrect cause OpenALPR library to abort early.  The .NET wrapper may not catch that.  If that solves it, please let me know and I'll file an issue on GitHub.

Calum Fletcher

unread,
Jul 1, 2015, 7:13:39 AM7/1/15
to open...@googlegroups.com, calum.fletc...@gmail.com
Still can't get past the 'The specified module could not be found' error! I've copied all my DLL's to the bin but still no luck. Tried hard-coding the values as above but doesn't seem to make any difference. Although, I can't even get it to debug into the code at all, it just bombs before I even get to that point. A further note, I am using this within an MVC project, not a console application as I have seen alot of examples use.. - is it able to be used in that way?

Cheers

Curtis DeHaven

unread,
Jul 1, 2015, 9:50:32 AM7/1/15
to open...@googlegroups.com
Calum, somewhere along the way, I did get what you're seeing.  Couldn't even set an initial breakpoint - module could not be found right away...  I think you're still missing a dll somewhere.  You might try running prcmon to try and see which file it's looking for that fails.

I don't have much experience with MVC.  I ended up abandoning my console test app and am now using one of the demo forms apps - openalprnet-windemo.  I can compile it, it runs, but crashes when it tries to call recognize().  Not much info - it says something about an external error...  Perhaps the next step is to build/debug the dll - not looking forward to that...  On a good note, it gets past loading the dll and the bool IsLoaded() returns a true.

Curt
Message has been deleted

Daniel Camargo

unread,
Nov 6, 2015, 12:44:27 PM11/6/15
to OpenALPR, calum.fletc...@gmail.com
Any luck solving this issue? I am getting the same problem.

I've found this post but could not find the dlls mentioned: https://github.com/openalpr/openalpr/issues/114

Matt

unread,
Nov 9, 2015, 10:52:03 PM11/9/15
to OpenALPR, calum.fletc...@gmail.com
The DLLs you'll probably want (if you're using the precompiled binaries) should all be in one of these packages:
https://github.com/openalpr/openalpr/releases/tag/v2.2.0

"Dependency walker" is helpful for determining if something is missing.  Once you're in .NET, you want to make sure you're compiling with the correct architecture that matches your OpenALPR DLLs (i.e., x86_64 for 64-bit and Win32 for 32-bit)
Message has been deleted

Paweł Kaczmarczyk

unread,
Nov 10, 2015, 11:57:09 AM11/10/15
to OpenALPR, calum.fletc...@gmail.com
Which version of Visual Studio are you using? I think you need 2015.

Daniel Camargo

unread,
Nov 11, 2015, 1:05:53 PM11/11/15
to OpenALPR, calum.fletc...@gmail.com
This is the scenario:

I've download the 64 bits version of the OpenALPR 2.2.0
I've installed the vc_redist.x64.exe

I've copied the libs and dll into my sample 64 WPF project folder (as in the first Screenshot).

And then, I've created this method:

public List<Result> GetPlateNumberCandidates(Country country, string imagePath)
        {
            var ass = Assembly.GetExecutingAssembly();
            var assemblyDirectory = Path.GetDirectoryName(ass.Location);

            var configFile = Path.Combine(assemblyDirectory, "openalpr", "openalpr.conf");
            var runtimeDataDir = Path.Combine(assemblyDirectory, "openalpr", "runtime_data");

            using (var alpr = new AlprNet(country == Country.EU ? "eu" : "us", configFile, runtimeDataDir))
            {
                if (!alpr.IsLoaded())
                {
                    throw new Exception("Error initializing OpenALPR");
                }

                var ret = new List<Result>();

                var results = alpr.Recognize(imagePath);
                foreach (AlprPlateResultNet alprPlateResultNet in results.Plates)
                {
                    var points = alprPlateResultNet.PlatePoints;

                    var bestPlate = alprPlateResultNet.BestPlate;
                    ret.Add(new Result()
                    {
                        Confidence = bestPlate.OverallConfidence,
                        PlateNumber = bestPlate.Characters,
                    });
                }

                return ret;
            }

        }


And I always get this exception: 

An exception of type 'System.IO.FileNotFoundException' occurred in openalpr.wpf.exe but was not handled in user code

Additional information: Could not load file or assembly 'openalpr-net.dll' or one of its dependencies. The specified module could not be found.
Screenshot 2015-11-11 10.57.42.png
Screenshot 2015-11-11 10.58.38.png

Matt

unread,
Nov 11, 2015, 9:38:25 PM11/11/15
to OpenALPR, calum.fletc...@gmail.com
You probably don't want to add all those OpenALPR DLLs to your project.   You just need to add it to the folder where your executable is compiled (i.e., the Debug or Release folder).  

When your .Net program starts, it needs to have access to the OpenALPR code so it can execute the logic.  That's all in those native DLLs.  The openalpr-net.dll is just a wrapper that points into those native DLLs.  Your program will first look in the current folder, then the system path.  So, if it can't find it, it gives you that error message.  Adding the files to your .NET project won't do anything unless you also set it up to be copied into the build folder (I think build action -> copy to output directory would do it).

-Matt

Paweł Kaczmarczyk

unread,
Nov 12, 2015, 3:41:16 PM11/12/15
to OpenALPR, calum.fletc...@gmail.com
Do like Matt says. You only need to add one reference, openalpr-net.dll. Then paste these files to the same folder in which you have your .exe:
openalpr-net.dll
liblept170.dll
opencv_ffmpeg300.dll
opencv_world300.dll
But before you do any of that, install Visual Studio 2015.
I just did and tried that and it works.

alpr220.png

Curtis DeHaven

unread,
Nov 13, 2015, 10:38:58 AM11/13/15
to OpenALPR, calum.fletc...@gmail.com
I just did what Pawel did and I sure got a lot further - still not there, though...

When I go to step over the call to Recognize(), I get an exception...

An unhandled exception of type 'System.AccessViolationException' occurred in openalpr-net.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The code...

string config = "C:\\Users\\cdehaven\\Documents\\Visual Studio 2015\\Projects\\openalpr_32bit\\openalpr.conf";


string country = "us";


AlprNet alpr = new AlprNet(country, config, "");


AlprResultsNet res = alpr.Recognize("C:\\Users\\cdehaven\\Documents\\Visual Studio 2015\\Projects\\openalpr_32bit\\samples\\us-1.jpg");

           



Paweł Kaczmarczyk

unread,
Nov 13, 2015, 2:53:27 PM11/13/15
to OpenALPR, calum.fletc...@gmail.com
Did you change the runtime_data folder in the configuration file? If not, you have to pass it in the constructor as the third parameter. That's the only thing i can think of.

Curtis DeHaven

unread,
Nov 13, 2015, 3:43:47 PM11/13/15
to OpenALPR, calum.fletc...@gmail.com
Wow!  YOU are good, Pawel.  That's exactly it.  I changed that 3rd parameter as follows and it came right up...

AlprNet alpr = new AlprNet(country, config, "C:\\Users\\cdehaven\\Documents\\Visual Studio 2015\\Projects\\openalpr_32bit\\runtime_data");

 
Thanks for your help.  This is pretty cool...

Curt


Paweł Kaczmarczyk

unread,
Nov 13, 2015, 5:23:17 PM11/13/15
to OpenALPR, calum.fletc...@gmail.com
I'm glad i could help :)

Henrik Lauridsen

unread,
Jan 16, 2016, 5:12:18 AM1/16/16
to OpenALPR, calum.fletc...@gmail.com
Hi,
I had the same problem Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies, but fixed from your message.
I was missing the 3 files liblept170.dll opencv_ffmpeg300.dll and opencv_world300.dll
Thanks a lot.

Shamsuddin Ladha

unread,
Sep 16, 2016, 7:10:30 AM9/16/16
to OpenALPR, calum.fletc...@gmail.com

I am getting the same error, despite doing as suggested in your post.


AlprNet alpr = new AlprNet("eu", "H:\\content\\openalpr.conf", "H:\\content\\runtime_data");

System.AccessViolationException was unhandled
  HResult=-2147467261
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=openalpr-net
  StackTrace:
       at alpr.Alpr.{ctor}(Alpr* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* )
       at openalprnet.AlprNet..ctor(String country, String configFile, String runtimeDir)
       at invoke_openalpr_net.Program.Main(String[] args) in ...

Few points to note
. If I provide an invalid path then I do not get any error (obviously I cannot do anything in that case).
. I was able to invoke the C++ version of the openalpr dll.
. Another thing I have noted is that I have to provide all three arguments to AlprNet, i.e., there are no overloaded constructors.

Any insights would be very helpful.

Thank you.

Matt

unread,
Sep 19, 2016, 3:40:58 PM9/19/16
to OpenALPR
Which DLLs are you using?  Did you compile them yourself, or did they come from the GitHub "release" ?  Are you running in release or debug mode?

Shamsuddin Ladha

unread,
Sep 20, 2016, 4:20:54 AM9/20/16
to OpenALPR
Thank you Matt for the reply.

I compiled the dlls myself and I am running in release mode.

Shamsuddin Ladha

unread,
Sep 26, 2016, 6:37:31 AM9/26/16
to OpenALPR
As a work around I wrote a simple P/Invoke wrapper for using the dll. That seem to work fine for the time being.
Reply all
Reply to author
Forward
0 new messages