The news comes courtesy of Variety: 

Of all the cast of characters that have been announced, Neil Patrick Harris definitely stands out. When you think of returning cast members like Keanu Reeves and Carrie-Anne Moss and new additions like Yahya Abdul-Mateen, all of them seem to be a natural fit in the action-heavy Matrix universe. Neil Patrick Harris doesn’t exactly fit that mould. He’s most known for playing the playboy, Barney Stinson in the HIMYM sitcom — a role that has now become iconic. He also did a terrific job as the over the top and eccentric Count Olaf in Netflix’s A Series of Unfortunate Events. Also, who can forget that time he hosted the Oscars and performed a magic trick? Yes, he’s been in gritty, dramatic projects before, most notably as the creepy ex-boyfriend in David Fincher’s Gone Girl. But even there the character sort of operated in a zone that’s not too dissimilar from Harris’ usual stuff, in a twisted sort of way. So it’s intriguing that Lana Wachowski has decided to cast him in Matrix 4. It always excites me when comedic actors decide to play more serious roles — just thinking about Steve Carell’s performance in Foxcatcher makes my stomach lurch. But for all we know, I could be overthinking this. Harris could very well be cast in a comedic role and there’s nothing wrong with that. Matrix 4 is set to be helmed by Lana Wachowski (without her sibling Lily Wachowski), with a script by Lana Wachowski, Aleksandar Hemon and David Mitchel.

Matrix 4  Barney Stinson From How I Met Your Mother Joins Cast - 94