简体   繁体   English

在 mscorlib.dll 中发生 System.IO.FileNotFoundException?

[英]System.IO.FileNotFoundException occuring in mscorlib.dll?

Background: I am working on a very large Suite that contains about 12 different sub-applications.背景:我正在开发一个非常大的套件,其中包含大约 12 个不同的子应用程序。 My goal is to take one of these sub-applications and create its own executable with all the DLLs embedded into the EXE file.我的目标是采用这些子应用程序之一并创建自己的可执行文件,并将所有 DLL 嵌入到 EXE 文件中。 So far, I have been able to embed most of the DLLs through the following steps到目前为止,我已经能够通过以下步骤嵌入大部分 DLL

1) Add the DLLs to the project in a local Folder and set them to "Embedded Resources". 1)将DLL添加到本地文件夹中的项目并将它们设置为“嵌入式资源”。

2) Add those DLLs to the References tab and set the Copy Local property to False 2) 将这些 DLL 添加到 References 选项卡并将 Copy Local 属性设置为 False

3) Add those DLLs to the Resources.resx file 3) 将这些 DLL 添加到 Resources.resx 文件中

I have also created a new Program.cs file and set the entry point to the main function located in the desired sub application assembly.我还创建了一个新的 Program.cs 文件并将入口点设置为位于所需子应用程序集中的主函数。 My problem is that the DLL file that is used to run the entire suite cannot be embedded into the EXE of the subapplication because I keep getting a System.IO.FileNotFoundException in the mscorlib.dll with the stack frame set at System.AppDomain.ExecuteAssembly.我的问题是用于运行整个套件的 DLL 文件无法嵌入到子应用程序的 EXE 中,因为我在 mscorlib.dll 中不断收到 System.IO.FileNotFoundException,堆栈框架设置为 System.AppDomain.ExecuteAssembly . I however can completely avoid this exception is I set the "Suite.dll" Copy Local property to true.但是,我可以完全避免此异常,因为我将“Suite.dll”复制本地属性设置为 true。

Here is my assembly resolver handler, but it never gets hit since the exception is occuring in managed code before the Main function is even executed.这是我的程序集解析器处理程序,但它永远不会被命中,因为在 Main 函数执行之前,托管代码中就发生了异常。

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
        {
            string resourceName  = new AssemblyName(args.Name).Name+".dll";

            string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
            {
                Byte[] assemblyData = new Byte[stream.Length];
                stream.Read(assemblyData, 0, assemblyData.Length);
                return Assembly.Load(assemblyData);
            }
        };

Is this even preventable?这甚至可以预防吗? How do I resolve this dependency so that I can embed my Suite DLL file into my sub-application EXE?如何解决这种依赖关系,以便我可以将我的 Suite DLL 文件嵌入到我的子应用程序 EXE 中? Please comment if more information is required and I will edit the question.如果需要更多信息,请发表评论,我将编辑问题。 Thanks!谢谢!

Reduce your main function to setting up AssemblyResolve and then calling another function in another class that does whatever you have main doing now. 将您的主要功能简化为设置AssemblyResolve,然后在另一个类中调用另一个函数,该类可以执行您现在主要要做的任何事情。

In order to use this trick, neither main, nor the containing class may reference any of the packed assemblies, else they can't be resolved when main is jitted. 为了使用此技巧,main或包含类都不能引用任何打包的程序集,否则当main被固定时就无法解析它们。

我遇到了同样的问题,原因是我不小心从项目文件夹中删除了Newtonsoft.Json.dll

与项目参考和 Nuget 包相比,检查您的 App.Config 中是否存在过时或完全错误的条目

暂无
暂无

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

相关问题 抛出异常:mscorlib.dll 中的“System.IO.FileNotFoundException” - Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll 在 mscorlib.dll 中发生“System.IO.FileNotFoundException” - 'System.IO.FileNotFoundException' occurred in mscorlib.dll 连接到MongoDB时,mscorlib.dll中发生“ System.IO.FileNotFoundException” - 'System.IO.FileNotFoundException' occurred in mscorlib.dll when connect to MongoDB mscorlib.dll 中发生类型为“System.IO.FileNotFoundException”的未处理异常 - An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll 抛出异常:mscorlib.dll C3 Discord.NET bot 中的“System.IO.FileNotFoundException” - Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll C3 Discord.NET bot 引发异常:mscorlib.dll中的“ System.IO.FileNotFoundException”(“找不到文件'cache-journal.db'。”) - Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll (“Could not find file 'cache-journal.db'.”) 抛出异常:mscorlib.dll,Visual Studio C# 中的“System.IO.FileNotFoundException” - Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll, Visual studio C# mscorlib.ni.dll中发生类型为'System.IO.FileNotFoundException'的第一次机会异常-Windows Phone - A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll - windows phone 在mscorlib.dll中永久发生的System.Threading.ThreadAbortException - System.Threading.ThreadAbortException occurred in mscorlib.dll occuring persitently 'System.IO.FileNotFoundException' - 'System.IO.FileNotFoundException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM