At least one element in the source array could not be cast down to the destination array type  
Author Message
Luis Esteban Valencia Muñoz





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

Hello, I am trying to pass someparameters to my reporting services web service.

This report has 2 dropdown and one checkbox , I am trying to convert an arraylist to parametervalue[]

This is teh code-

ArrayList al = new ArrayList();

al.Add(DropDownList1.SelectedValue.ToString());

al.Add(DropDownList2.SelectedValue.ToString());

for (int i = 0; i < CheckBoxList1.Items.Count; i++)

{

if (CheckBoxList1.ItemsIdea.Selected)

{

selectected.Append(CheckBoxList1.ItemsIdea.Value);

selectected.Append(",");

al.Add(CheckBoxList1.ItemsIdea.Value.ToString());

TiposCompetenciasSeleccionadas++;

}

}

ParameterValue[] reportParameterValues3 = null;

reportParameterValues3 = (ParameterValue[])(al.ToArray(typeof(ParameterValue))); --- ERROR




.NET Development33  
 
 
nobugz





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

You've got an awful lot of casts in this code. I'm guessing the problem is in getMarketData(). Perhaps you have a DBNull in your query/table


 
 
Alexander Prokofyev





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

As I know, you can't get array of one type (ParameterValue in this case) from ArrayList using ToArray() method if you have added objects of another type to ArrayList.

So, you should convert strings to ParameterValue before adding them to the list.


 
 
HarryBedi





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

Nah, I dont have a DBNull.

I really cant offer more of a reason at all. Except for does it have something to do with I am converting the double array using the ToArray method

Cheers

H


 
 
Pandiarajan.net





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

Thanks a lot.

 
 
nobugz





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

Yes, ArrayList.ToArray() needs to convert a list of objects to double. If one of those objects isn't convertible, you'll get this exception. Take a good look at the contents of argsln in the de****. Or convert them one by one by casting them to double to find the one that is causing the error.


 
 
HarryBedi





PostPosted: .NET Base Class Library, At least one element in the source array could not be cast down to the destination array type Top

i guys thanks for all your help.

I have managed to solve the problem with your inputs...

Regards,

HB