.Net bug with <%= %> and option parameters?



  • I just had the weirdest fucking bug I've ever seen, and still haven't technically "solved" it. Has anyone come across this? Can anyone repro it?

    Setup (don't know how many of these factors matter)

    • VS2012
    • VB.net
    • Website project
    • Publish compiled to single .dll (ie: don't deploy the .vb files)
    • IIS 6.1 (running on either Windows 7 or Windows Server 2012)
    • Project uses .Net 4.6.1

    Code:

    • a class in App_Code with a Shared function with the signature Public Shared SomeFunction(ByVal s as String, Optional ByVal o as Object = Nothing, Optional ByVal b as Boolean = False) as String
    • Let the function return any non-empty string, it doesn't matter. Say it just returns "Echo " & s
    • A user control (.ascx)-- maybe this also is repro in a straight .aspx page, don't know
    • On the control, emit the directive <%= TheClass.SomeFunction("_GiveMeMoney") %>

    If you run this code locally before compiling / deploying anything, you'll see "Echo _GiveMeMoney". All good.

    But if you "publish" the project-- compiling all the code into a .dll-- and then try to visit that page-- well, then the function is NEVER CALLED AT ALL.

    No "Ambiguous function" warning. Nothing in the Event log. Nothing. If you set a breakpoint on SomeFunction, it never gets hit. It's like .Net suddenly decides "Well, fuck that, I'm not calling that function".

    But if you fill in even the FIRST optional parameter, it works. <%= TheClass.SomeFunction("_GiveMeMoney", Nothing) %>, gets you "Echo _GiveMeMoney".

    At first I thought this was environmental-- it was only happening in one project, on one server. But then I copied the compiled website to my local server, and can reproduce.

    I'm fuckstumped on this one.


  • kills Dumbledore

    @lorne-kates said in .Net bug with <%= %> and option parameters?:

    a class in App_Code with a Shared function with the signature Public Shared SomeFunction(ByVal s as String, Optional ByVal o as Object, Optional ByVal b as Boolean) as String

    Optional arguments in VB need a default value. Are you missing that or did you just not mention it in the post?
    Public Shared SomeFunction(ByVal s as String, Optional ByVal o as Object = Nothing, Optional ByVal b as Boolean = false) as String

    In a more strongly typed language I'd assume you just missed it out, but VB can do funny things sometimes



  • @jaloopa said in .Net bug with <%= %> and option parameters?:

    Are you missing that or did you just not mention it in the post?

    Edited the post to reflect...


  • kills Dumbledore

    @lorne-kates In that case I've got nothing



Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.