停止运行编译器 [英] Stop running compiler

查看:113
本文介绍了停止运行编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用CodeDomProvider创建了dll,在编译之后我想删除那个dll文件,但它显示了对路径'c:\sathish \ abc的访问权限。 dll'被拒绝错误。



如何解决这个问题?



我有什么试过:



我的代码是



Hi all,
I was created the dll using CodeDomProvider,after compile that dll i want delete that dll file, but it's showing Access to the path 'c:\sathish\abc.dll' is denied error.

How to Slove this ??

What I have tried:

my code is

ICodeCompiler compiler = provider.CreateCompiler();
                CompilerParameters parameter = new CompilerParameters();
                string strCompilerfilepath = @"c:\sathish\abc.dll";

                string finalPath = string.Empty;

                parameter.OutputAssembly = finalPath = Path.Combine(strCompilerfilepath, forClassName + ".dll");

                parameter.ReferencedAssemblies.Add("System.dll");
                parameter.ReferencedAssemblies.Add("System.Text.RegularExpressions.dll");
                parameter.GenerateExecutable = false;
                parameter.GenerateInMemory = false;
                parameter.TreatWarningsAsErrors = false;

                CompilerResults results = compiler.CompileAssemblyFromSource(parameter, sb.ToString());
 if (!results.Errors.HasErrors)
 {
	 if (File.Exists(finalPath))
                    {                       
                        File.SetAttributes(finalPath, FileAttributes.Normal);
                        File.Delete(finalPath);
                    }
 }

推荐答案

我不知道你为什么要删除刚才的文件创建(甚至在更改它的属性后)。



尝试使用 ICodeCompiler.CompileAssemblyFromSource方法(CompilerParameters,String)(System.CodeDom.Compiler) [ ^ 相反。使用 CreateCompiler 已过时。



被拒绝访问的可能原因可能是文件仍处于锁定状态编译器实例是活动的。



使用过时的样式时,您可以尝试调用Component.Dispose方法(布尔值)(System.ComponentModel) [ ^ ]释放非托管资源,如文件句柄。

[/ EDIT]
I don't know why you want to delete a file that has just been created (and even after changing it's attributes).

Try to use ICodeCompiler.CompileAssemblyFromSource Method (CompilerParameters, String) (System.CodeDom.Compiler)[^] instead. Using CreateCompiler is obsolete.

A probable reason for the denied access might be that the file is still locked while the compiler instance is active.

When using the obsolete style you can try to call the Component.Dispose Method (Boolean) (System.ComponentModel)[^] to release the unmanaged resources like file handles.
[/EDIT]


您好,



显示的代码有不匹配的路径。

Hi,

The code shown has a mismatch path.
string strCompilerfilepath = @"c:\sathish\abc.dll";
Path.Combine(strCompilerfilepath, forClassName + ".dll");





您的字符串 strCompilerfilepath 必须是目录的路径。

.NET函数 Path.Combine 创建一个像这样的新路径





Your string strCompilerfilepath must be a path to a directory.
The .NET function Path.Combine makes a new path as like this one

c:\sathish\abc.dll\className.dll





如果abc.dll是一个文件而不是一个目录,你无法删除你的最终路径。



If abc.dll is a file and not a directory, you cannot delete your final path.


我解决了我的问题。

我加载那个程序集后创建了dll并存储在bin文件夹中到app域。

现在程序集已成功加载并卸载该app域。



谢谢你的所有命令。
I Solve my Problem.
I create the dll and stored in a bin folder, after I load that assembly to app domain.
now the assembly loaded successfully and unload that app domain.

thank you all your commands.


这篇关于停止运行编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆