简体   繁体   English

系统找不到dll

[英]System cannot find dll

I have a dll called test and within test.dll, I'm referencing another dll called process. 我有一个名为test的dll,并且在test.dll中,我引用了另一个名为process的dll。 Now when I try loading test.dll, I get the error "System cannot find process.dll. Please help 现在,当我尝试加载test.dll时,出现错误“系统找不到process.dll。请帮助

Assembly u = Assembly.LoadFile(@"C:\test\test.dll");

        Type t = u.GetType("Test.Process");
        MethodInfo m = t.GetMethod("ProcessFile");

        try
        {
            object[] myparam = new object[1];
            myparam[0] = @"C:\test\testFile.csv";

            result = (string)m.Invoke(null, myparam);

            Console.WriteLine(result);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            Console.WriteLine(ex.InnerException.ToString());
            System.Threading.Thread.Sleep(100000);
        }

Use LoadFrom instead of LoadFile . 使用LoadFrom代替LoadFile Quote from the documentation : 文档引用:

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. 使用LoadFile方法可以加载和检查具有相同标识但位于不同路径中的程序集。 LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile不会将文件加载到LoadFrom上下文中,也不会像LoadFrom方法那样使用加载路径解析依赖项。 LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; 在这种有限的情况下,LoadFile很有用,因为LoadFrom不能用于加载具有相同标识但路径不同的程序集。 it will load only the first such assembly. 它只会加载第一个这样的程序集。

Assembly u = Assembly.LoadFrom(@"C:\test\test.dll");
...

I suspect you want LoadFrom instead of LoadFile in this case. 我怀疑在这种情况下,您需要LoadFrom而不是LoadFile The difference is that the extra path ( c:\\test ) will be added to the "load from" context which will then be used for dependencies such as process.dll . 不同之处在于,将额外路径( c:\\test )添加到“加载自”上下文中,然后将其用于诸如process.dll依赖项。

At the moment, it's trying to resolve process.dll without taking c:\\test into consideration. 目前,它正尝试在不考虑c:\\test情况下解析process.dll Read the linked documentation for more information. 阅读链接的文档以获取更多信息。

Get test.dll fileInfo: 获取test.dll fileInfo:

 FileInfo fileInfo = new FileInfo("test.dll");

and use fullName to load the assembly: 并使用fullName加载程序集:

Assembly assem = Assembly.LoadFile(fileInfo.FullName);

I hope it helps. 希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在参考中找不到 System.Drawing.dll - Cannot find System.Drawing.dll in reference 找不到库 System.Runtime.dll 以使用 ReadOnlySpan<t></t> - Cannot find library System.Runtime.dll for using ReadOnlySpan<T> 无法加载文件或程序集“ * .dll”,系统找不到指定的文件 - Could not load file or assembly “*.dll” , The system cannot find the file specified 系统找不到dll - The system can not find the dll 找不到dll或依赖项 - Cannot find dll or dependency 在模块System.dll C#中找不到类型System.Runtime.InteropServices.StandardOleMarshalObject - Cannot find type System.Runtime.InteropServices.StandardOleMarshalObject in module System.dll C# 在Windows Phone 8.1模块System.dll中找不到类型System.ComponentModel.TypeConverter - Cannot find type System.ComponentModel.TypeConverter in module System.dll, Windows Phone 8.1 System.IO.FileNotFoundException:无法加载文件或程序集。 系统找不到文件SharpSvn.dll - System.IO.FileNotFoundException: Could not load file or assembly. The system cannot find the file SharpSvn.dll 在模块System.dll中找不到类型System.Collections.Specialized.NameObjectCollectionBase - Cannot find type System.Collections.Specialized.NameObjectCollectionBase in module System.dll 没有行号的错误在模块System.dll中找不到类型System.ComponentModel.TypeDescriptionProvider - Error with no line number Cannot find type System.ComponentModel.TypeDescriptionProvider in module System.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM