.net hates me today, as well as my co worker Rob.
It all started earlier today, when Rob called me over and showed me the following error in an application he has under development. His portion consists of a class library, a custom data access layer, and a service wrapper, using asmx / soap / xml.
System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Web.Services.Protocols.HttpServerType..ctor(Type type) at System.Web.Services.Protocols.HttpServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
Normally, when Rob asks for help, I sweep in for the massive buzzkill, with my super awesome programming skillz. Not today. Today marks the second bug I have found, going back six years, on the .net framework. The first relates to public properties of master pages, and that if you have one, and you have batch compilation enabled, your site just kind of stops working sometimes. Not so cool.
This one would prove to be even weirder. The really kooky part, and what disturbs me to no end, is that Hello World! saved the day. Let's start with a simple custom type of Gumball:Public Class Gumball Private _color As GumballColor
Private _size As Integer
Private _name As StringPublic Property Color() As GumballColor
End GetSet(ByVal value As GumballColor) Me._color = value
Public Property Size() As Integer
End GetSet(ByVal value As Integer) Me._size = value
Public Property Name() As String
End GetSet(ByVal value As String) Me._name = value
Public Overrides Function Equals(ByVal obj As Object) As BooleanDim gb As New Gumball() gb = DirectCast(obj, Gumball)
If gb._color = Me._color And gb._name = Me._name And gb._size = Me._size Then
End IfEnd FunctionEnd Class
Public Enum GumballColor
So, there's our simple Gumball class. Now, we'll create our service wrapper which allows us to touch and poke a Gumball from across the big mighty Internet. What we do doesn't really matter. The important part here is that a public sub (void) with no arguments, combined with a public method that returns the same type that it takes as an argument, gives the error at the top of this page.
Imports System.Web.ServicesImports System.Web.Services.Protocols<WebService(Namespace:="http://tempuri.org/")> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Public Class wsRobInherits System.Web.Services.WebService
<WebMethod()> _Public Function InsertWithArgs(ByVal g As Gumball) As Gumball
Dim g2 As New Gumball()Return g2
<WebMethod()> _Public Sub InsertWithoutArgs() End Sub
What the methods do doesn't really matter, and what the class does really doesn't matter. Putting a breakpoint anywhere doesn't help, nor does anything end up in the server log. Running it in IIS 6.0, or the VS debugger yields the same results. However, if you put the stock Hello World! back in, it works like a champ.
I tried this, and it yields the same result:
<WebMethod()> _Public Function SelectWithNoArgs() As GumballDim g As New Gumball()
g.Color = GumballColor.Blue
g.Name = "AwesomeGumball"
g.Size = 5Return g
What matters isn't really whether you use Hello World! or SelectWithNoArgs (my example); the InsertWithArgs(g as Gumball) as Gumball now works like a champ. We googl'ed around and tried looking for this error, and found a few people who encountered it, but no one was very helpful in diagnosing / resolving. If anyone has found a fix to this problem, please let me know, as it was annoying and wasted a lot of time.
It's a sad day in programming when you can have a problem, but put
Public Function HelloWorld() As String
Return "Hello World"
back in, and it all works again. Very sad. Again, if you have a web service that contains a public method with a return type that's the same as the input argument's, you can't execute a public sub web method (a.k.a. void for my c# homies), unless you add in Hello World, or the SelectWithNoArgs thing that I cranked out.
One thing I'm going to check on is whether or not this is limited to HTTP Post / HTTP Get, since we haven't checked this yet to see if SOAP gets kicked back the same way.