我构build一个CodeCompileUnit,下面的代码输出一个C#源代码文件,一个.dll,我可以从程序集中得到一个实例:
TextWriter tw = new IndentedTextWriter(new StreamWriter(filePath + ".cs",false)," "); provIDer.GenerateCodeFromCompileUnit(compileUnit,tw,new CodeGeneratorOptions()); tw.Close(); CompilerParameters cp = new CompilerParameters { GenerateInMemory = true,GenerateExecutable = false}; cp.ReferencedAssemblIEs.Add("MyProgram.exe"); cp.OutputAssembly = filePath + ".dll"; CompilerResults cr = provIDer.CompileAssemblyFromfile(cp,filePath + ".cs"); MyType instance = (MyType)Activator.CreateInstance(cr.CompiledAssembly.GetTypes()[0]);
到现在为止还挺好。 现在我想避免生成这些文件:
CompilerParameters cp = new CompilerParameters { GenerateInMemory = true,GenerateExecutable = false}; cp.ReferencedAssemblIEs.Add("MyProgram.exe"); //cp.OutputAssembly = filePath + ".dll"; CompileResults cr = provIDer.CompileAssemblyFromDom(cp,compileUnit);
这将引发fileNotFoundException。 它在我的 temp文件夹中查找x32savit.dll(或类似的),但它不在那里。 如果我取消注释OutputAssembly,它会失败,但在该path上。
从C#/ WPF应用程序重新启动机器
如何使用windows SDK更新“其他时钟”设置
如何刷新目录作为修复fileSystemWatcher的一种方法
在windows中,当我在windows资源pipe理器中双击某个文件时会发生什么?
Sr.net开发人员需要知道数据结构吗?
如何在VB.NET中切换Caps Lock?
如何使用fileSystemWatcher监视新驱动器
以编程方式更改IE开发人员工具用户代理设置
从C#应用程序获取windowsExplorer中的当前select?
我如何等待windows进程及其subprocess全部退出?
原来是命名空间的错误。 这里有一个很好的例子。
添加下面的代码在调试时非常有帮助。
string errorText = String.Empty; foreach (CompilerError compilerError in compilerResults.Errors) errorText += compilerError + "n";
总结以上是内存溢出为你收集整理的CompileAssemblyFromDom抛出FileNotFoundException全部内容,希望文章能够帮你解决CompileAssemblyFromDom抛出FileNotFoundException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)