开发者

Prevent CompileAssemblyFromSource from generate temp files with duplicate file name

开发者 https://www.devze.com 2023-03-27 23:02 出处:网络
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.

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 whil开发者_Go百科e 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消