Pirsig and Rand both embed their philosophy within fiction, thus leaving you befuddled and oddly unsatisfied: "Did I just read a philosophical treatise or fiction?"
But ZAMM and Atlas Shrugged certainly felt to me a bit dishonest in that these works are primarily delivery devices for the authors' philosophical ideas. Other authors inject philosophy and ethics into their "straight" fiction, such as the philosophical rant-free work of Tolkien (LOTR = a treatise against fascism) and Stephen King (The Stand = a treatise against organized religion), but their philosophies never smack you in the face. [edit: grammar]
I suspect that what goes wrong is not writing a philosophical treatise in the form of fiction - what goes wrong is that the One True Philosophy is treated as a Mary Sue within the context of the fiction.