0

我正在尝试在我的 WCF 应用程序中运行 OpenALPR,但目前我无法运行它。我不断得到

“无法加载文件或程序集‘openalpr-net.DLL’或其依赖项之一。找不到指定的模块。”

IIS 以及 VS2015-Community 版本中的错误。

我已关注以下线程,但无法解决我的问题。

https://groups.google.com/forum/#!topic/openalpr/7ADDNSkhoLE
https://groups.google.com/forum/#!topic/openalpr/Nu26YmbOSng

在整个互联网上,它都说这是平台问题,这就是我现在所拥有的。

Visual Studio 2015 WCF Application
Reference to openalpr-net.dll (64bit) in my project
Copied opencv_world300.dll, opencv_ffmpeg300_64.dll, liblept170.dll into bin folder manually
Included openalpr.conf in the root folder of WCF application
Included runtime_data folder in the root folder of WCF application
Set 'unblock' for all the dll's, and files under runtime_data folder
Project > Properties > Build > General > Platform target > x64
Project > Properties > Build > Configuration > Active(Debug)
Project > Properties > Build > Platform > Active (x64)

我还将应用程序发布到本地 iis 服务器,我将应用程序池设置为与 .net 4.0 的集成模式,我尝试启用和禁用“启用 32 位应用程序”,但这两种方法都不适合我。

当我在解决方案资源管理器中选择 Service.svc 并调试应用程序时,在 WCF 测试客户端中出现以下错误

Error: Cannot obtain Metadata from http://localhost:55460/AlprService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:55460/AlprService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:55460/AlprService.svc'. The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '
Server Error in '/' Application.
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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies. The specified module could not be found.]   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25   System.Reflection.Assembly.Load(String assemblyString) +34   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49[ConfigurationErrorsException: Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies. The specified module could not be found.]   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +76   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +139   System.Web.Compilation.BuildManager.ExecutePreAppStart() +176   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +882[HttpException (0x80004005): Could not load file or assembly 'openalpr-net.DLL' or one of its dependencies. The specified module could not be found.]   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716

我可以从下载文件夹中的 readme.txt 文件中运行以下命令而没有任何问题,并且可以看到结果 'alpr -p tx -n 30 samples/us-4.jpg'

此外,当我在 IIS 上打开启用 32 位应用程序时,我收到错误消息说 projectname.dll 未加载,否则将是“openalpr-net.DLL”不丢失。我正在将 Release - x64 发布到 IIS。

任何人都可以建议或指出我正确的方向吗?我在这里做错了什么?

4

1 回答 1

0

我在同样的问题上摸不着头脑,但终于让它工作了;

确保添加对 64 位 openalpr-net.dll 的引用。

在您的 WCF 代码中,确保您使用此代码从程序集所在的同一文件夹中加载 conf 文件和 runtime_data 文件夹

 public string AssemblyDirectory
    {
        get
        {
            var codeBase = Assembly.GetExecutingAssembly().CodeBase;
            var uri = new UriBuilder(codeBase);
            var path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }
   }
        String config_file = Path.Combine(AssemblyDirectory, "openalpr.conf");
        String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data");

        using (var alpr = new AlprNet("us", config_file, runtime_data_dir))

将您的 wcf 发布到本地或远程 IIS。假设您将其发布到 c:\inetpub\wwwroot\alprService。将 openalpr.conf 文件和 runtime_data 文件夹复制到 c:\inetpub\wwwroot\alprService\bin\ 文件夹。将 liblept170.dll、opencv_ffmpeg300_64.dll 和 opencv_world300.dll 这 3 个 dll 复制到托管服务器上的 system32 文件夹中。您会在 github 上的 openalpr-net.dll 所在的文件夹中找到这些 dll。

让我知道这是否对您有用。我可以发送图像并返回匹配列表。

现在您应该能够加载 wcf 服务而不会出现错误。

于 2016-08-23T13:57:45.927 回答