Any reason why you used a different file name in the painter to what you're setting at run time in the code snippet you provided?
Clutching at straws here ... can you try a relative or maybe UNC path for your filename? That's another difference I noted from my code to yours.