用C写了一个标准的dll。在开发环境及测试服务器上该dll可以正常加载(动态加载),但部署到虚拟主机中却无法加载。Dll的路径都正确,且是绝对路径。代码如下://动态加载dll类
class DllInvoke
    {
        [DllImport("kernel32.dll",SetLastError=true)]
        private extern static IntPtr LoadLibraryEx(String libPath,IntPtr hFile,Int32 dwFlag);        [DllImport("kernel32.dll")]
        private extern static IntPtr GetProcAddress(IntPtr lib, String funcName);        [DllImport("kernel32.dll")]
        private extern static bool FreeLibrary(IntPtr lib);        private IntPtr hLib;        public DllInvoke(String libPath)
        {
           
           问题就在这,老说加载失败(hLib=0),Marshal.GetLastWin32Error()为:183.
           换成LoadLibraryEx也是一样。
           

            hLib = LoadLibrary(libPath);//该路径传进来没有问题,是绝对路径
            //hLib = LoadLibraryEx(libPath, IntPtr.Zero, 16);
            if (hLib == IntPtr.Zero)
            {
                throw new Exception("LoadLibary failure!");
            }
        }        public Delegate GetDelegate(String func, Type t)
        {
            IntPtr api = GetProcAddress(hLib, func);            return api == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer(api, t);
        }        ~DllInvoke()
        {
            FreeLibrary(hLib);
        }
    }   class Encrypter
   {
       delegate Int32 DEncrypter(ref Byte source, Int32 sourceLen);
       private String dllPath = ConfigurationManager.AppSettings.Get("Encrypt");
       private DllInvoke invoke;       public Encrypter()   {            
             String dllFilePath = System.Web.HttpContext.Current.Server.MapPath(dllPath);
             invoke = new DllInvoke(dllFilePath);           
        }        public bool Encrypt(Byte[] source)
        {
            DEncrypter encrypt = (DEncrypter)invoke.GetDelegate("Encrypt", typeof(DEncrypter));            return encrypt(ref source[0], source.Length) == 0 ? true : false;
        }
   }
这段程序在开发环境及部署到测试服务器上都成功运行,但已部署到虚拟主机上就报错。
xdjm们哪个知道是什么原因啊,急啊,都已经4天了,头大啊

解决方案 »

  1.   

    已经跟虚拟主机供应商沟通过,bin下添加了everyone的读取权限。
      

  2.   

    坐等高手来啊,不过一般都不会碰到需要用C的DLL的情况~
      

  3.   

    Error 183 is ERROR_ALREADY_EXISTS貌似看一些文章说 loadlibrary的时候也需要调用系统api createfile 猜测需要写的权限?
      

  4.   

    那可以分析一下环境的差异比如说 操作系统、 iis配置、 文件夹权限、 操作用户权限 罗列一下寻找差异的东西,在本地复现一下线上的环境,看看是否也是错误的
      

  5.   

    结贴,问题产生原因是:dll依赖msvcr100.dll,把这个依赖去掉就没问题了。