I guess that you have already restart Minecraft so if that doesn’t work, restart your system and see if it works for you.
Re-adding your friend is also one solution that you can try out. Remove the person that you want to connect with from your friend list and then add him/her back.
Solution 2: Change the settings
Navigate to the Xbox official website.
Now on the website, click the Xbox One/Windows 10 Online Privacy tab.
Now, find Join multiplayer games and you have to ensure that it should be set to Allow.
Set it to Allow if it is not and then click Submit.
Solution 3: Disable Antivirus
Antivirus may block certain features of the game. It happens with many applications that it gets block or some of the features get block by the antivirus. You can disable the antivirus for some time and then check if the error disappears or not.