Tuesday, July 17, 2007

A "System.IO.FileNotFoundException" error occurs when a Web service is called

Problem

When you call a Web service in a Microsoft ASP.NET Web application, you may receive the following error:

System.IO.FileNotFoundException

Cause

This error can occur if either of the following conditions is true:

· The worker process does not have permissions to read to the process Temp directory, and the worker process does not have permissions to write to the process Temp directory.

· There are compilation errors in the code that XmlSerializer generated.

Resolution

Worker Process Account Permissions on the Temp Directory

To resolve this problem, the ASP.NET worker process account (the ASPNET account or the NETWORK SERVICE account if your application is deployed on Internet Information Services [IIS] 6.0) must have read access and write access on the Temp directory.

Note If you use impersonation, the impersonated user must have full access on the Temp directory.

To assign required permissions to the worker process account on the Temp directory, follow these steps:
1. In Microsoft Windows Explorer, locate the %windir%\temp directory.
2. Right-click %windir%\temp, and then click Properties.
3. In the Properties window, click the Security tab.
4.Click Add, type ServerName\ASPNET, and then click OK.

Note Replace ServerName with the name of the Web server.

Replace ASPNET with NETWORK SERVICE if you deployed your application on IIS 6.0.
5.Under Allow, click to select the Full Control check box, and then click OK.


Find Compiler Errors in the Code That XmlSerializer Generated

To find errors that are generated by the compiler, you must add a switch to the Web.config file to keep compiler-generated files. To do this, follow these steps:
1.Open the Web.config file in a text editor, such as Notepad.
2.Add an XmlSerialization.Compilation switch to the system.diagnostics section of the code, as follows:
<configuration>
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4">
</add>
</switches>
</system.diagnostics></configuration>
3. Run the client application.

The client application calls the Web service.
4.Verify that the %windir%\temp directory has the _tmpname.00.cs file and the _tmpname.out file.

The _tmpname.00.cs file is the generated source. The _tmpname.out file should have the compiler errors.

Note Enable the read permissions and enable the write permissions to the worker process account (ASPNET or NETWORK SERVICE) to write %tmpname% files in the Temp directory.

Source: Microsoft

No comments: