System.IO.FileNotFoundException When Invoking A Web Service

The exception would be on a (different) strange looking file name each time I would run the web service. For example the file name would be 4drv23rf.dll. Below is the entire error:

System.IO.FileNotFoundException: File or assembly name 4drv23rf.dll, or one of its dependencies, was not found.
File name: "4drv23rf.dll"
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase,
Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound,
Assembly locationHint, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized,
Evidence assemblySecurity, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity)
   at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
   at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
   at System.Xml.Serialization.Compiler.Compile()
   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
   at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings)
   at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type,
LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context,
HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context,
HttpRequest request, HttpResponse response, Boolean& abortProcessing)
=== Pre-bind state information ===
LOG: Where-ref bind. Location = 4drv23rf.dll
LOG: Appbase = file:///c:/inetpub/wwwroot/WebService1
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
LOG: Policy not being applied to reference at this time (private, custom, partial, 
or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WINDOWS/Temp/4drv23rf.dll.

As you can see from above, the file was always located in my C:\WINDOWS\Temp\ directory. I really have no idea what this file is or why it’s placed in this directory. I thought all temporary ASP.NET files were saved to the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files location.

After using Google for about an hour to search for solutions, I really did not find anything that seemed to fit my particular problem. Then on the way out the door (from work), I mentioned it to my co-worker. It seems he has had the same issue.

The Solution

It seems that the ASP.NET Machine Account (<machine name>\ASPNET) needs to have read/write access to the Windows temporary directory to create these temporary dll’s. Simply go to that directory, bring up the properties dialog and click on the Security tab. Click Add and add the ASPNET account. Make sure “Write” is checked and press Apply.

Tip By: David McCarter/ Mike Carr