一般的程序找Dll文件是按照入下顺序:首先在EXE当前目录中找,然后在Windows目录中找,再然后在system32中找。
怎么我写的Dll文件放在Windows或System32中会报错呢?到底是Dll的问题还是EXE的问题?是不是能设置查找的目录?

解决方案 »

  1.   

    我是直接运行EXE文件,只是把EXE文件里的DLL放到Windows\system32中去了
      

  2.   

    你exe里调用dll时写路径啦吗?
    如果没有写路径才按你说的那种方法寻找最主要是运行exe后提示什么信息?
      

  3.   

    我是直接引用的Dll。
    错误信息是:应用程序中发生了未处理的异常。如果单击“退出”,应用程序将忽略此错误并常识继续。如果单击“退出”,应用程序将立即关闭。
    找不到文件或程序集名称“Socg.转换.Table_To_Tree”,或找不到它的一个依赖项。。
    详细信息:
    有关调用实时(JIT)调试而不是此对话框的详细信息,
    请参阅此消息的结尾。************** 异常文本 **************
    System.IO.FileNotFoundException: 找不到文件或程序集名称“Socg.转换.Table_To_Tree”,或找不到它的一个依赖项。
    文件名: “Socg.转换.Table_To_Tree”
       at 人员管理.人员管理.人员管理_Load(Object sender, EventArgs e)
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)=== Pre-bind state information ===
    LOG: DisplayName = Socg.转换.Table_To_Tree, Version=1.0.2061.43068, Culture=neutral, PublicKeyToken=null
     (Fully-specified)
    LOG: Appbase = E:\cw\Source\C#\人员管理\bin\Debug\
    LOG: Initial PrivatePath = NULL
    Calling assembly : 人员管理, Version=1.0.2062.1015, Culture=neutral, PublicKeyToken=null.
    ===LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Post-policy reference: Socg.转换.Table_To_Tree, Version=1.0.2061.43068, Culture=neutral, PublicKeyToken=null
    LOG: Attempting download of new URL file:///E:/cw/Source/C#/人员管理/bin/Debug/Socg.转换.Table_To_Tree.DLL.
    LOG: Attempting download of new URL file:///E:/cw/Source/C#/人员管理/bin/Debug/Socg.转换.Table_To_Tree/Socg.转换.Table_To_Tree.DLL.
    LOG: Attempting download of new URL file:///E:/cw/Source/C#/人员管理/bin/Debug/Socg.转换.Table_To_Tree.EXE.
    LOG: Attempting download of new URL file:///E:/cw/Source/C#/人员管理/bin/Debug/Socg.转换.Table_To_Tree/Socg.转换.Table_To_Tree.EXE.************** 已加载的程序集 **************
    mscorlib
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
    ----------------------------------------
    人员管理
        程序集版本: 1.0.2062.1015
        Win32 版本: 1.0.2062.1015
        基本代码: file:///E:/cw/Source/C%23/人员管理/bin/Debug/人员管理.exe
    ----------------------------------------
    System.Windows.Forms
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
    ----------------------------------------
    System
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
    ----------------------------------------
    Socg.常用窗体.SQL连接窗体
        程序集版本: 1.0.2060.27985
        Win32 版本: 1.0.2060.27985
        基本代码: file:///E:/cw/Source/C%23/人员管理/bin/Debug/Socg.常用窗体.SQL连接窗体.DLL
    ----------------------------------------
    Socg.数据连接.SQL连接
        程序集版本: 1.0.1122.10554
        Win32 版本: 1.0.1122.10554
        基本代码: file:///E:/cw/Source/C%23/人员管理/bin/Debug/Socg.数据连接.SQL连接.DLL
    ----------------------------------------
    System.Data
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
    ----------------------------------------
    System.Drawing
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
    ----------------------------------------
    System.Xml
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
    ----------------------------------------
    System.EnterpriseServices
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.enterpriseservices/1.0.5000.0__b03f5f7f11d50a3a/system.enterpriseservices.dll
    ----------------------------------------
    mscorlib.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/mscorlib.resources/1.0.5000.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll
    ----------------------------------------
    System.Windows.Forms.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/winnt/assembly/gac/system.windows.forms.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll
    ----------------------------------------************** JIT 调试 **************
    计算机的配置文件(machine.config)的 
     system.windows.forms 节中必须设置 jitDebugging 值。
    编译应用程序时还必须启用\r\n调试。\r\n\r\n例如: \r\n\r\n<configuration>\r\n    <system.windows.forms jitDebugging="true" />\r\n</configuration>\r\n\r\n启用 JIT 调试后,任何未处理的异常\r\n都将被发送到此计算机上注册的 JIT 调试器,\r\n而不是由此对话框处理。\r\n
      

  4.   

    肯定拉,这个DLL是程序静态引用的,所以存在路径问题,要把DLL分发到WINDOWS目录下,需要用到gacutil.exe工具
      

  5.   

    可以看一下《Inside C#,2nd》第1章中对私有程序集和共享程序集的解释以及gacutil.exe工具的使用。