Tuesday, February 7, 2012

Unable to generate a temporary class(result=1) - .Net


Sometimes trying to customize the configurations to fit your needs by not following the default configuration could lead us to interesting unknown specifics. This time I was meddling with the root config to redirect the temp files to be stored on f:\ rather than the default c:\.  Here is the result of doing so.



Server Error in '/XYZ/XYZZ' Application.




Server was unable to process request. ---> Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\Windows\TEMP\uao6dgcc.0.cs' could not be found
error CS2008: No inputs specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\Windows\TEMP\uao6dgcc.0.cs' could not be found
error CS2008: No inputs specified

if you need to understand the config hierarchy  - configuration file hierarchy.

The above exception clearly tells us that changes done to the root config is not enough and there are places still to look at. In most of the cases you won’t see this issue since your default directory would have the appropriate write privileges.


After researching for a while here are few things that needs to be taken care

XmlSerializer createsC# (.cs) files and compiles them into .dll files in the directory named by the TEMP environment variable; serialization occurs with those DLLs. This seems strange to me and I think the root config should have overridden this. 

For detailed info on XML Serialization

Here is the configuration that would fix it. KB Article link - http://support.microsoft.com/kb/934529


<system.xml.serialization>
<xmlSerializer tempFilesLocation="Full path of the tempfolder" />
 </system.xml.serialization>

Provide read/writeprivileges for the Temp folder to the ASPNET account. When ASP.NET Web Services process WebMethods, the identity that is used most frequently to gain access to the system Temp folder is the local ASPNET account, which is the default account under which ASP.NET applications run.


However, if you have configured your application to use impersonation in itsWeb.config file, the thread can also use the identity of any caller. If this isthe case, all potential calling identities must have read/write privileges tothe Temp folder. A likely calling identity is the Internet Information Services(IIS) application's anonymous account (typically the ISUR_xxx account).The thread may also use the IWAM_xxx account.

I have also read that precompilation of xml serialized classes could help. I haven't tried it. If you try and it worked, Please post it in the comments. Good luck with it.

Happy Coding!!!!