title: CSharpCodeGenerator "Could not find file C:\Windows\Temp\...dll"
body: <p>I was awoken today by an alarming text message from the server monitor service that one of my servers was down, and has been for the past 7 hours.</p>
  
  <p>The server runs a WCF web-service hosted in IIS.</p>
  
  <p>I checked in IIS and my Application Pool was stopped. There was nothing in the Event Logs on the server.</p>
  
  <p>My application catches all errors and writes them to the filesystem. I saw there were over 7300 <code>FileNotFoundException</code> reports. They all look like this:</p>
  
  <pre><code>System.IO.FileNotFoundException("Could not find file 'C:\Windows\TEMP\fmhq0eve.dll'.")
  mscorlib
  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
  at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
  at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
  at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
  at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
  at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
  at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
  at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
  at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
  at System.ServiceModel.Dispatcher.UnwrappedTypesXmlSerializerManager.BuildSerializers()
  at System.ServiceModel.Dispatcher.UnwrappedTypesXmlSerializerManager.GetOperationSerializers(Object key)
  at System.ServiceModel.Dispatcher.SingleBodyParameterXmlSerializerMessageFormatter.EnsureSerializers()
  at System.ServiceModel.Dispatcher.SingleBodyParameterXmlSerializerMessageFormatter.GetOutputSerializer(Type type)
  at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.CreateBodyWriter(Object body)
  at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.SerializeReply(MessageVersion messageVersion, Object[] parameters, Object result)
  at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.SerializeReply(MessageVersion messageVersion, Object[] parameters, Object result)
  at System.ServiceModel.Dispatcher.DispatchOperationRuntime.SerializeOutputs(MessageRpc&amp; rpc)
  at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
  at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
  at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
  at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
  </code></pre>
  
  <p>I saw this error was reported on StackOverflow in the past, and has a variety of causes, mostly to do with Serializer caching, however the code in the stack trace is entirely handled by WCF.</p>
  
  <p>The server was left completely alone for over a month. The last Windows Update reboot was on the 21st, 5 days before these exceptions happened. I can think of no other cause.</p>
  
  <p>Why did this problem start happening and what can we do about it? Is this a bug in WCF?</p>