asmx WebService insisting on methods it calls in other classes having nullable parameters
I was trying to simplify some code in a library shared between a winform and a webapp (written by someone else) by taking several methods/properties that were nullable, but for which nullable values were never passed in/nulls were never consumed into non-nullable ones.
This worked fine in the winform app, and the webapp doesn't have any compile time problems but when I first ran it, it failed reporting an error that it couldn't find the old version of the method that took DateTime?
parameters, despite the fact that the values being passed were non-nullable DateTime
s. When I added back an overload with DateTime?
parameters it worked only to generate an error elsewhere in the code due to a property that had been changed from int?
to int
.
After confirming that an overload with DateTime?
parameters would work as a fix, I commented 开发者_Go百科the overload back out to try and figure out why it was insisting on calling that version. At some point while I was fiddling with it (doing forced rebuilds, etc), it suddenly stopped generating the errors even though I'd reverted the two .cs files to the version where they were initially failing. At this point it's working, but I have no idea what went wrong initially or how it was fixed, and I'm very leery of continuing on until I know what happened.
Approximate error message (from memory):
Method not found: 'null
NameSpace.StaticClass.StaticMethod( IFoo foo, IBar[] bar, DateTime? padStart, DateTime? padEnd )'.
Actual error message:
Method not found: 'System.Nullable
1 NameSpace.OtherClass.get_Number()'.`
Method in MyWebService.asmx:
[WebMethod( EnableSession = true )]
public string DoStuff( string jsonFoo, string startDate, string endDate )
{
try
{
IFoo foo = Deserialize<IFoo>( jsonFoo );
IBar[] bar = null;
DateTime padStart = DateTime.Parse(startDate);
DateTime padEnd = DateTime.Parse(endDate);
StaticClass.StaticMethod( foo, bar, padStart, padEnd );
}
}
Method in StaticClass:
public static void StaticMethod( IFoo foo, IBar[] bar, DateTime padStart, DateTime padEnd )
{
}
In the interest of clearing out the obvious problems first - did you rebuild any client side proxies/stubs that were built against the service? The client code could still have been generating service requests to the v1 service definition rather than the shiny new v2 one. Just a thought?
It sounds like it's just an issue with how the .NET runtime handles dynamic compilation in a Website project. In a Web Application you have to rebuild it anytime you make changes, and the whole app gets compiled into a .dll like other projects. In a Website with dynamic compilation, the runtime basically determines how your pages get separated into .dll's and when they need to be rebuilt. Since your situation involved static methods in what sounds like is a separate project/.dll, but the page in your site never changed, the runtime probably just never re-linked against the updated .dll. Then if at some point you made a change to the page that would have caused it to be recompiled, it would suddenly recognize the new methods in your static class. Of course at this point, it's just guessing ;)
If you have a problem like this again, though, I'd recommend right-clicking the Website in Solution Explorer and doing a "Rebuild"
精彩评论