0

I've got the unenviable task of cleaning up a rather messy VB.Net client. The general plan is to move all calculations to WebServices, and I can see exactly how to do this, but it involves passing a large number of different variables to the WebServices.

I chose to use an ArrayList as I've worked with them heavily in Java, and have had no issues passing ArrayLists between the C# (ASMX) WebService and a C# client (Windows Forms-based).

However, the VB.Net client app doesn't want to pass the ArrayList into the WebServices, giving a compiler error "Value of type 'System.Collections.ArrayList' cannot be converted to '1-dimensional array of Object'."

4
  • @Andrey why sure List<T> is great but ArrayList works just fine. Commented Sep 23, 2010 at 14:41
  • @msarchet what do you mean works fine? List<T> is better in all ways. Why to use ArrayList then? Commented Sep 23, 2010 at 14:49
  • @Andrey I need to pass multiple data types to the WebServices because I'm doing a whole host of calculations on them, so typeless ArrayLists are better suited Commented Sep 23, 2010 at 14:58
  • Well, you still can use List<object> but it is useless except you can do Linq with it. if you pass several different objects they should derive from one single parent (not System.Object) and you will have List<ThatParentClass> and reduce amount of typecasts Commented Sep 23, 2010 at 15:18

2 Answers 2

3

Just call ToArray() on your ArrayList when you pass it to the web service.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, but still no joy. Same error on this line: Dim results As ArrayList = webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()) Where quoteValues is the filled ArrayList
Okay, to clarify this did solve the problem when passing the list TO the WebService, but I then got the same issue bringing the List back FROM the WebService. The solution is to define a new ArrayList for the results, then use AddRange like so: Dim results As ArrayList; results.AddRange(webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()))
0

Thanks to everyone who helped but I managed to find the answer. The issue relates to VB.Net's handling of WebService object passes; nothing to do with the C#. As ck said, I had to call '.ToArray()' on the ArrayList when I passed it to the WebService, but then had to use 'AddRange()' on a fresh ArrayList to get the results into it. Code is as follows:

Dim results As New ArrayList;
results.AddRange(webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()))

Or generically:

Dim a as New ArrayList;
a.AddRange(webService.Method(sendingAL.ToArray()))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.