防止 CompileAssemblyFromSource 生成具有重复文件名的临时文件

编程入门 行业动态 更新时间:2024-10-26 13:30:05
本文介绍了防止 CompileAssemblyFromSource 生成具有重复文件名的临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的 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/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/a/37136996/5682035:

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

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

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:39:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   临时文件   CompileAssemblyFromSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!