Prevent CompileAssemblyFromSource from generate temp files with duplicate file name

馋奶兔 提交于 2019-12-23 10:49:15

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/7026939/prevent-compileassemblyfromsource-from-generate-temp-files-with-duplicate-file-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!