I have a stylesheet in the application ~/Content/theme/style.css . It is referenced in my application using standard binding as such:
bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/font-awesome/font-awesome.css", "~/Content/theme/style.css"));
Now I used the Sass compiler (Libsass) so that I can change the style.css output file to a custom output file if necessary.
So basically I'm doing something like this.
CompilationResult compileResult = SassCompiler.CompileFile(Server.MapPath(Path.Combine(WebConfigSettings.RootSassPath, "style.scss"), options: new CompilationOptions { SourceMap = true, SourceMapFileUrls = true });
and then I save it.
string outputPath = Server.MapPath(WebConfigSettings.ThemeOutputPath); if (System.IO.File.Exists(outputPath)) System.IO.File.Copy(outputPath, string.Format("{0}.bak", outputPath), true); System.IO.File.WriteAllText(Server.MapPath(WebConfigSettings.ThemeOutputPath), compileResult.CompiledContent);
However, with interruptions, I get the following terrible access error: "The process cannot access the C: .... \ style.css file" because it is being used by another process. " (Note: This happens on the line File.WriteAllText )
This does not make sense, because I do not open any streams in the file and do not perform what I believe is one atomic operation using File.WriteAllText .
Now I also noticed that this error is especially likely when I use two different browsers to modify this file in sequence.
My guess is that one of two things happens.
Or:
a. The package wrapper somehow locks the file because it was changed when it updates the packages and does not release the lock or
b. Since two different connections are accessing the file, somehow the lock is stored in them.
So, does anyone come across something similar? Any suggestions on how I can solve this problem?
PS: I tried using HttpRuntime.UnloadAppDomain(); as a hacker way to try and release any locks in the file, but that doesn't seem to help.