how to handle this exception in c#..

Posted by Gopal_nivas under ASP.NET on 11/19/2010 | Points: 10 | Views : 1523 | Status : [Member] | Replies : 2
hi..
i was converting xml value to pdf..

while converting this i got this exception"Index and length must refer to a location within the string. Parameter name: length"..

this is my code:
private static Bitmap returnBitMap(string sPixelData, Bitmap oBitmap, int iWidth, int iHeight)
{
try
{
iWidth=400;
iHeight=700;
string sCurrentPixelColor = String.Empty;

if (sPixelData != String.Empty)
{
oBitmap = new Bitmap(iWidth, iHeight);


int i = 0;
for (int ix = 0; ix < iHeight; ix++)
{

for (int iy = 0; iy < iWidth; iy++)
{
sCurrentPixelColor = sPixelData.Substring(i * 6, 6);
oBitmap.SetPixel(iy, ix, ColorTranslator.FromHtml("0x" + sCurrentPixelColor));
i++;
}


}


}
return oBitmap;
}
catch (Exception ex)
{

throw ex;
}

}


-----------------

how to handle this..

need ur suggestions..

regards
gopal.s




Responses

Posted by: Lalji_mer on: 11/19/2010 [Member] Bronze | Points: 25

Up
0
Down
Try to paste in a copy of the log file generated when trying to output to PDF. The log files are probably in C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\LogFiles

LP MER

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/19/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Gopal,

I think in your code the following line is Problem..

sCurrentPixelColor = sPixelData.Substring(i * 6, 6);

In this line check the substring length.May be the error occured in this line.
Refer those links..its also have same type of error..

http://www.c-sharpcorner.com/forums/ShowMessages.aspx?ThreadID=62634

http://forums.asp.net/t/922189.aspx

Cheers :)


Thanks,
T.Saravanan

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response