Thursday, 23 October 2008

.NET Web Services - Parser Error Fix

Have you ever received this message? It usually displays when a web service has been installed using an installer (MSI) - This is ensuring your name spaces are correct however!

Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error details
and modify your source file appropriately.

Parser Error Message: Could not create type 'Namespace.ProjectName.Class'.

Source Error:

Line 1: <%@ WebService Language="C#" CodeBehind="Class.asmx.cs"
Class="Namespace.ProjectName.Class" %>

Im not 100% sure this is a guaranteed bug (Occurs within VS 2005), but there is a workaround.

1. When generating your installer, its usually common to right click the Installer in the Solution Explorer and Select: "Add > Project Output...". You can then select the relevant projects and outputs required.

2. Once this has been done, double click one of the project outputs in solution explorer, and you'll see the directory structure upon where the installer will install certain information to.

3. If you are experiencing this issue, you will see project output files (Content files and Primary Output) finding their presence within the root directory of the web application! This is not what we want, and this is why we are getting the Parser Error, because its trying to find the associated web service class within the bin folder.

4. To resolve, simply delete the "Primary Output" output, and re-add this output within the bin folder. This can be achieved by navigating within the bin folder, right clicking, and adding the project output again.

5. Ensure the "Content Files" project output remains within the web applications root directory. This is usually the default.

No comments: