SQL Server – Configure a new publication on the SQL 2014 database that is part of an availability group

I like setting up a publication (transactional replication) on a SQL Server 2014 database that is part of an availability group. We have a main replica and a secondary one (not readable).

On the case, I already have another publication running. The distributor runs outside the availability group, even on a different domain.

Initially, the distributor installation was done on the other replica (which is currently the secondary). In addition, the other existing publication was originally created on the other hosts. This is the first publication I need to create after performing a failover from the availability group to the secondary.

Execute the following command on the database to publish

EXEC sp_replicationdboption @dbname = mydatabase & # 39;
@optname = N & # 39 ;,
@value = N / A true;

I have received the following error:

Msg 20028, Level 16, State 1, Procedure sp_MSpublishdb Line 56 [Batch Start Line 0]
The dispenser has not been installed correctly. Can not enable the database for publishing.

I wonder why this is happening because I'm already publishing on another database without any errors and I'm also working properly.

Checked management logs do not help because nothing has been saved. After checking the distributor, I also found that the publisher is correctly registered.

Any ideas what could be problems here?