【问题标题】:Dllimport to works in console application, but not in ASP.NET websiteDllimport 可以在控制台应用程序中工作,但不能在 ASP.NET 网站中工作
【发布时间】:2014-04-29 09:42:08
【问题描述】:

我从未使用过 DLL 导入,所以我遇到了一个有趣的问题。

我正在尝试在一个爱好项目中实现 Ghostscript.NET。所以我做了一个叫做 GhostscriptSharp 的项目。这个项目有一个名为 Ghostscript32.cs 的文件,它像这样导入 DLL:

        #region Hooks into Ghostscript DLL
        [DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
        private static extern int CreateAPIInstance(out IntPtr pinstance, IntPtr caller_handle);

        [DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
        private static extern int InitAPI(IntPtr instance, int argc, string[] argv);

        [DllImport("gsdll32.dll", EntryPoint = "gsapi_exit")]
        private static extern int ExitAPI(IntPtr instance);

        [DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")]
        private static extern void DeleteAPIInstance(IntPtr instance);

当我添加一个新的控制台测试项目时,引用 GhostscriptSharp 项目并将 gsdll32.dll 放在我的根目录中,然后像这样运行程序,它可以工作:

GhostscriptWrapper.GeneratePageThumb(TEST_FILE_LOCATION, SINGLE_FILE_LOCATION, 1, 100, 100);

但是,我需要这个才能在网络项目中工作。所以我在根目录下添加了gsdll32.dll,并添加了对GhostscriptSharp项目的引用。但是,然后我在这里收到错误:

An exception of type 'System.DllNotFoundException' occurred in GhostscriptSharp.dll but was not handled in user code

Additional information: Unable to load DLL 'gsdll32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

有什么办法解决这个问题吗?

这是我的解决方案文件夹的图像:

【问题讨论】:

标签: .net visual-studio dll .net-4.5 ghostscriptsharp


【解决方案1】:

我只会回答它,即使答案非常简单。

dll 文件必须在您的 bin 文件夹中的原因。如果不是默认的。

因此,我制作了以下脚本,使其正确地将其复制到 bin 文件夹中:

if exist "$(TargetDir)gsdll32.dll" goto :exit
   copy "$(ProjectDir)\..\Packages\GhostscriptSharp\gsdll32.dll" "$(TargetDir)"
:exit

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多