首页 新闻 会员 周边 捐助

动态编译源码的问题

0
悬赏园豆:20 [已关闭问题]

我使用如下代码进行源码动态编译:

//获取WSDL
                    WebClient wc = new WebClient();
                    Stream stream = wc.OpenRead(url + "?WSDL");
                    ServiceDescription sd = ServiceDescription.Read(stream);
                    ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                    sdi.AddServiceDescription(sd, "", "");
                    CodeNamespace cn = new CodeNamespace(@namespace);

                    //生成客户端代理类代码
                    CodeCompileUnit ccu = new CodeCompileUnit();
                    ccu.Namespaces.Add(cn);
                    sdi.Import(cn, ccu);
                    CSharpCodeProvider csc = new CSharpCodeProvider();
                    // ICodeCompiler icc = csc.CreateCompiler();  


                    //设定编译参数
                    CompilerParameters cplist = new CompilerParameters();
                    cplist.GenerateExecutable = false;
                    //cplist.GenerateInMemory = true;
                    cplist.GenerateInMemory = false;
                    cplist.OutputAssembly = assemblyname;

                    cplist.ReferencedAssemblies.Add("System.dll");
                    cplist.ReferencedAssemblies.Add("System.XML.dll");
                    cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                    cplist.ReferencedAssemblies.Add("System.Data.dll");

                    //编译代理类
                    CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu);

                    if (true == cr.Errors.HasErrors)
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                        {
                            sb.Append(ce.ToString());
                            sb.Append(System.Environment.NewLine);
                        }
                        throw new Exception(sb.ToString());
                    }                   

                    assembly = cr.CompiledAssembly;

 

---

编译完成后,在D:/CacheTemp/下能找到动态生成的DLL。但是,在

assembly = cr.CompiledAssembly;  这一步却发生异常,提示说未能找到程序集,没有授予运行权限。
这个该怎么处理呢?

mcjeremy的主页 mcjeremy | 初学一级 | 园豆:6
提问于:2008-12-01 15:57
< >
分享
其他回答(2)
0

web应用程序没有执行D:/CacheTemp/目录下代码的权限,把dll移动到bin目录下试试。

玉开 | 园豆:8822 (大侠五级) | 2008-12-01 17:35
0

将 ASPNET 账户添加到 D:/CacheTemp/ ,并赋予运行权限

eaglet | 园豆:17139 (专家六级) | 2008-12-02 06:31
0

学习了...

Jared.Nie | 园豆:1940 (小虾三级) | 2008-12-02 09:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册