Parser Error : Could not create type

55,865

Solution 1

I don't know if this is dragging something up from the dim and distant past, but I had this problem. I fixed it. So I thought I'd to share it.

When you create a web service in Visual Studio (I'm using 2010 but I'd imagine it's the same for others), it creates a file called Service1.asmx

You will be tempted to rename it to MyService.asmx (or whatever).

Then you'll look inside and see the line

public class Service1: System.Web.Services.WebService

which you'll change to

public class MyService: System.Web.Services.WebService

and then when you try running it, you get the error

Could not create type 'MyProject.MyService'

Because it still thinks the class is called Service1.

If you right click the .asmx file and select view markup, you'll see it still says:

<%@ WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.Service1" %>

change it to

<%@ WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.MyService" %>

save it, try it.

It worked for me.

Solution 2

I had the same problem and looked for it for a long time!

I tried a lot of things including the following:

None of those worked for me. After some searching, testing and cursing, I finally found the problem: The application (webservice) was incorrectly hosted.

Let me explain with a little background:

I had a project containing two solutions: One solution was the website that I made (html, javascript, etc), the other solution contained a folder with the business logic, the database model and the webservices. Obviously the webservices folder contained my .asmx files and code-behind for them.

  • Project
    • Data Core
      • Database Model
      • Business Logic
      • Webservices
        • myWebservice.asmx
    • Website

I was hosting these in the following way:

  • My website was hosted as a new site with the website folder as root folder
  • My webservices I was hosting as an application in my website, with the webservices folder as root

More visually:

  • IIS 7
    • My Website => Pointing at the "Website" folder
      • Webservices Application => Pointing at the "Webservices" folder in the Data Core

This resulted in the following url "http://website/webservices/myWebservice.asmx", which gave me the "Could not create type" error.

Now, after playing around a bit I tried hosting my webservice application starting with the data core as root, instead of the webservice folder.

Visually:

  • IIS 7
    • My Website => Pointing at the "Website" folder
      • Webservices Application => Pointing at the "Data Core" folder.

Obviously using the same url as before would give me a "File not found" error. However, using the following url "http://website/webservices/webservices/myWebservice.asmx",I finally got my working webservices page!

A small url breakdown:

  • http ://website/ => My website from the "Website" folder
    • webservices/ => Equivalent to the "Data Core" folder
      • webservices/ => The "webservices" folder in the "Data Core" folder
        • myWebservice.asmx => The webservice file in the "webservices" folder, in the "Data Core" folder

I assume that because I was hosting my webservices directly from the "webservices" folder in the Data Core, that the server could not find the compiled DLL of the webservices (which resides in the "bin" folder), since I was hosting at a deeper level.

After changing the configuration and hosting the webservices from the "Data Core" folder, the IIS server could "see" the bin folder and host the webservices succesfully. When using the correct url that is ^_^

I hope this is clear and helps you with you problems!

Solution 3

Another thing that can cause the problem. Is not creating an application for the project through the IIS itself. If the code is already on the server navigate to it in IIS from the left Connections pane. If the web site directory is still a yellow folder icon (and not a globe icon) you need to right-click on it and choose Convert to Application otherwise follow these steps...

Start -> Search For IIS

Open It!!

Right Click on the Default Web Site or the web site you are planning to publish the service to it.

Add application... Enter an Alias ex. "MyWebService" ... Choose the physical path. in my case was C:\inetpub\wwwroot\MyWebService which is my default web site path.

Then when you publish through Visual Studio choose that folder. or just copy your code files to it.

Share:
55,865
Meghan
Author by

Meghan

Updated on February 20, 2021

Comments

  • Meghan
    Meghan about 3 years

    I have created webservice and published it on local machine. Then I have uploaded it on server.

    Now while I tried to access webservice it gives following error :

    Parser Error Message: Could not create type 'webservice.myservice'

    Source Error: Line 1: <%@ WebService Language="C#" CodeBehind="myservice.asmx.cs" Class="webservice.myservice" %>

    I tried This link but unable to solve my problem.

    What should I do?

  • capn
    capn almost 12 years
    Thanks, I thought I was on the right path for fixing this and this answers confirms that. However, its not MyProject.MyService its MyNamespace.MyService. I guess I must be another visitor from the past as "This question is closed as it is unlikely to help any future visitors". Bollocks.
  • TheSilverBullet
    TheSilverBullet over 11 years
    This definitely helped me. I am trying to understand Web Services before getting into WCF.
  • TCS
    TCS about 11 years
    I had this issue and I had a different problem, so here is the solution for other frustrated people out there. If you change the build target folder, it will stop working. You have to copy the output of the build back to .\bin\
  • Ricardo C
    Ricardo C almost 9 years
    It should be noted that the class name should include the proper namespace, and changes to the namespace will also have this same effect.
  • Rafael Adnet Pinho
    Rafael Adnet Pinho over 5 years
    Thanks @hasan! You saved me a lot of time!
  • Marko Petričević
    Marko Petričević almost 5 years
    Great job btw, thats when perfection leads to errors =)