OSStatus error -50 on compiling for App Store

I recently had this error when compiling an app for the App Store.
It turns out that I had different certificates linked to the App Store provisioning profile and the development profile. They needed to be the same as the certificate used to compile the application.

And there is NO help available about how to fix this.
Apple support refused to admit it was possible, and couldnt help.
No-one on this forum could help.
I have spent 4 months being unable to build a deployable app.

Well it certainly is possible. If you happened to have created two development certificates for the same app ID with different expiration dates and then used one for the development profile and the other for the deployment profile. That would cause this type of error.