The briefly amusing high-school reunion comedy “The D Train” gets some things right. The right stuff exists mostly in the casting. Late 30-somethings James Marsden and Jack Black respectively co-star as the most popular and most unpopular guys in their high school, class of 1994.

Black’s Dan Landsman fancies himself chairman of the alumni committee that’s organizing a 20th anniversary high school reunion. No one else on the alumni committee agrees with this self-designation on Dan’s part.

“The D Train” gets a promising start as Dan and his former classmates work the phone bank, lobbying their peers to attend the reunion. Dan’s calls do not go well.

“No,” he tells one reunion prospect, “I don’t think I still suck.”

Meanwhile, Dan’s fellow alumni committee members treat him just as badly now as they did back in high school.

Following another unsuccessful night of reunion soliciting, the discouraged Dan gets a brilliant idea. Watching TV in the late-night darkness of his suburban home, he spots a former classmate in a national TV commercial. Oliver Lawless, the coolest guy in high school during the early ’90s, still cool and handsome, has become the spokesman for Banana Boat triple defense sunscreen for men.

It’s just a TV commercial. Not a TV series. Not a major Hollywood movie or even a well-received indie film. Even so, Dan gets stars in his eyes. A glorious fantasy takes hold of him. He imagines he’ll be the high school hero he never was if he can deliver Lawless to the reunion. He even tells the alumni committee that he and Lawless were friends in high school. They know it’s a lie.

“The D Train” loses its comic way, taking a grim turn from which it doesn’t recover. Dan, hoping to make his dream come true, turns into a serial liar, concocting a scheme to get Lawless.

The film leaves it to the audience to guess why Dan so desperately wants to make his fantasy real. Maybe a lifelong low self-esteem and lingering pain from high school push Dan into such drastic, risky behavior. It would have helped if the filmmakers spelled Dan’s motivation out clearly, illustrating what happened 20 and more years ago, but “The D Train” doesn’t go there.

Dan convinces his computer- and technology-phobic boss, Bill, that he needs to make a business trip to Los Angeles, where a beneficial deal for their company is waiting. The real reason for the trip is meeting Oliver and convincing him to attend the reunion.

The scheme gets more complicated when Dan’s boss decides he should go to Los Angeles, too. Jeffrey Tambor as Bill is another example of the film’s on-target casting. Tambor makes a fine straight man for Dan’s antics. And Marsden’s Oliver is just too cool for school, aptly handsome and almost poignant in his emptiness.

“The D Train” doesn’t fully exploit its good comic ingredients. Increasingly, Dan paints himself into an anxious, sad corner. As he drowns in his lies, the film that might have been a farce turns tragic. The downbeat scenario runs out of laughs.

The filmmakers devise a way out for Dan’s mess, but the escape doesn’t satisfy. “The D Train” stops short of whatever destination it may have had.