简体   繁体   中英

“Could not load type” in web service converted to VB.NET

I wrote a simple web service in C# using SharpDevelop (which I just got and I love).

The client wanted it in VB, and fortunately there's a Convert To VB.NET feature. It's great. Translated all the code, and it builds. (I've been a "Notepad" guy for a long time, so I may seem a little old-fashioned.)

But I get this error when I try to load the service now.

Parser Error Message: Could not load type 'flightinfo.Soap' from assembly 'flightinfo'.

Source Error:

Line 1:  <%@ WebService Class="flightinfo.Soap,flightinfo" %>

I have deleted the bins and rebuilt, and I have searched google (and stackoverflow). I have scoured the project files for any remnants of C#.

Any ideas?

In VB.NET, namespace declarations are relative to the default namespace of the project. So if the default namespace for the project is set to XY, everithyng between Namespace Z and End Namespace will be in the XYZ namespace. In C# you have to provide the full namespace name, regardless of the default namespace of the project. So if the C# project had the default namespace XY, the CS files would still include the namespace XY declaration. After converting to VB, if both the default namespace and the namespace declarations in the files stay the same you end up with classes in the XYXY namespace. So in your case, the Soap class is now in the flightinfo.flightinfo namespace. Thus there are three possible solutions:

  • change the asmx file to

  • remove the default namespace from the project

  • remove the namespace declarations from the vb files
<%@ WebService Class="flightinfo.Soap,flightinfo" %>

你的班级叫什么名字?

The problem may be cause by VB.NET & C# projects using different naming conventions for project assemblies and how the project namespace is used. At least that's were I would start looking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM