Multi-Subnet AG - DNS flips to secondary IP
This sounds a lot like you need to add MultiSubnetFailover=true to your connection strings.

See https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/sqlclient-support-for-high-availability-disaster-recovery#connecting-with-multisubnetfailover

That article explains fully why you need it enabled and even why you should specify it even if only using one subnet.

The main reason is that by default SQL Client will select the first IP address it learns about.  If DNS returns more than one IP address, it'll pick the first one.  Its possible for the the order from DNS to shift.  This setting overrides that behaviour.  Now SQL Client will attempt connections to all IP addresses and resolve which is the correct one to use.

You only need to update the connection string. No other code changes are required.