Failed to install Icinga2 Agent

We have lots of zones in our environment. We have a script that is taking from CMDB and getting the API key for each zone. The problem is that for hosts is working and for others no. I get the following message:

I have also tried with 2.10.3 (that doesn’t require .NET 4.6)

If I install the agent and then execute the script all is OK. I could not find a pattern why for some hosts are working and for others not.

Did someone else had this problem?