Can you put in some log statements to determine exactly which line of the script is failing?
Can you catch the exception and display the exception message/text?
Looking at the code, it does not check to verify whether this line results in good data:
var rawdata = Inet1.GetURL("<your URL>", 1);
If there is bad data, for example empty or not png data, then this line will probably fail:
cip.LoadPNGFromBuffer(rawdata);