I had the same issue when my application was running fine in development mode, but gave error 1502 when attempted to build an exe.
Found the reason being a broken VI in an instrument driver class that I used in my project. The broken VI was an "Example.vi" in the driver class, however this "Example.vi" was never used in my application, it was used as a standalone VI to test driver functionality.
Somehow having that broken(but unused) VI being part of the class that I used in my application caused the build to fail. By fixing the broken VI and build became successful.
The same issue does not occur if the broken VI is inside a library.
To prevent this from happening again to see the error after a long build process, I have created a VI to search for broken VI(s) within my project dependent classes before the build process.