防止 CompileAssemblyFromSource 生成具有重复文件名的临时文件 [英] Prevent CompileAssemblyFromSource from generate temp files with duplicate file name

查看:21
本文介绍了防止 CompileAssemblyFromSource 生成具有重复文件名的临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WCF 应用程序使用在运行时编译的代码来计算报告的某些值.我正在使用 CSharpCodeProvider.CompileAssemblyFromSource 来编译代码.如果客户端(Silverlight 应用程序)在计算另一个报告时请求报告,则 CSharpCodeProvider.CompileAssemblyFromSource 生成具有重复名称的临时文件,导致 IOException(文件 'C:\Windows\TEMP\uviewdyd.out' 已经存在.")

My WCF application uses code compiled in run time to calculate some values of a report. I'm using CSharpCodeProvider.CompileAssemblyFromSource to compile the code. If the client (a Silverlight application) request a report while another report is being calculated the CSharpCodeProvider.CompileAssemblyFromSource generates temp files with duplicated name, what lead to a IOException ("The file 'C:\Windows\TEMP\uviewdyd.out' already exists.")

有谁知道如何防止这种情况发生?

Does anyone know how to prevent this?

推荐答案

我认为没有.看起来所有三个变体(文件、DOM 和源)都创建了临时文件(来源).
最好的方法似乎是为每个编译使用不同的临时路径.请参阅https://stackoverflow.com/a/37136996/5682035:

I don't think there is. It looks like all three variants (file, DOM and source) create temp files (source).
The best way seems to use different temp paths for each compilation. See https://stackoverflow.com/a/37136996/5682035:

CSharpCodeProvider prov = new CSharpCodeProvider();
CompilerParameters parms = new CompilerParameters();
parms.TempFiles = new TempFileCollection(tempdir);

这篇关于防止 CompileAssemblyFromSource 生成具有重复文件名的临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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