Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Value of type '1-dimensional array of String' cannot be converted to ArrayOfString

Thread Tools Display Modes
Old 05-09-2011, 08:26 AM
sallymadeira sallymadeira is offline
Join Date: May 2011
Posts: 2
Default Value of type '1-dimensional array of String' cannot be converted to ArrayOfString

I have looked and googled every forum with no luck. I am using Express 10 environment and trying to call a webservice to upload documents. The last two parameters on InsertDocument function is of type BCOps.ArrayofString.
I have the following:

'Dim fieldnames As New List(Of String)
        'fieldnames.Add("BABC Request ID")
        'fieldnames.Add("BCR Num")
        'fieldnames.Add("Display File Name")

        'Dim fieldvalues As New List(Of String)
        'fieldvalues.Add("Loan Statements")
        'fieldvalues.Add("Participation Settlement")

        Dim fieldnames() As String = {"accountnumber",
                "indexdate", "captureby",
                "capturedate", "filetype", "doctype",
                "Account", "BABC Request ID", "BCR Num", "Display File Name"}

        Dim fieldvalues() As String = {"", "", "", "application/pdf", "1", "babc/system", "", "babc/system", "",
                                  "Loan Statements", "Participation Settlement", Account, BABCRequestID, BCRNum, FileName}

        Console.WriteLine("DEBUG: -----------------------------------------------------------------")
        Dim fileDocId As Long = objClient.insertDocument(APP_NAME, APP_KEY, USER_NAME, ORG_ID, imgData, fieldnames, fieldvalues)
        Console.WriteLine("DEBUG: -----------------------------------------------------------------")
I tried to do a Generic List and it still did not work. I went into the Advanced Properties of the Service Reference and changed collection type to Generic.List and still does not work. The Web Service Logic for insert document is as follows and I am hoping someone can help.

 <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", ""),  _
     System.Runtime.Serialization.CollectionDataContractAttribute(Name:="ArrayOfString", [Namespace]:="http://tempuri.org/", ItemName:="string"),  _
     System.SerializableAttribute()>  _
    Public Class ArrayOfString
        Inherits System.Collections.Generic.List(Of String)
    End Class
  Public Function insertDocument(ByVal appName As String, ByVal appKey As String, ByVal userName As String, ByVal orgID As Long, ByVal image() As Byte, ByVal fieldNames As BCOps.ArrayOfString, ByVal fieldValues As BCOps.ArrayOfString) As Long
            Dim inValue As BCOps.insertDocumentRequest = New BCOps.insertDocumentRequest()
            inValue.Body = New BCOps.insertDocumentRequestBody()
            inValue.Body.appName = appName
            inValue.Body.appKey = appKey
            inValue.Body.userName = userName
            inValue.Body.orgID = orgID
            inValue.Body.image = image
            inValue.Body.fieldNames = fieldNames
            inValue.Body.fieldValues = fieldValues
            Dim retVal As BCOps.insertDocumentResponse = CType(Me,BCOps.BCOpsSoap).insertDocument(inValue)
            Return retVal.Body.insertDocumentResult
        End Function
Partial Public Class insertDocumentRequestBody
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=false, Order:=0)>  _
        Public appName As String
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=false, Order:=1)>  _
        Public appKey As String
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=false, Order:=2)>  _
        Public userName As String
        <System.Runtime.Serialization.DataMemberAttribute(Order:=3)>  _
        Public orgID As Long
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=false, Order:=4)>  _
        Public image() As Byte
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=5)> _
        Public fieldNames As BCOps.ArrayOfString
        <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=false, Order:=6)>  _
        Public fieldValues As BCOps.ArrayOfString
If there is any other information I need to provide please let me know.
Reply With Quote
Old 05-09-2011, 08:53 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500

You're passing String(). The web service code wants ArrayOfString. I know the name "ArrayOfString" makes it sound like it's a string array, but the only thing that's going to work with a string array is String().

You noticed that ArrayOfString inherits from List(Of String) and tried that class. Inheritance doesn't work in that direction. Let's use an analogy.

"Dog" is a base class, like List(Of String) is here. If I ask you to bring me a dog, you could bring me a poodle or a labrador and satisfy the criteria. "Labrador" is a derived class of Dog, like ArrayOfString is here. If I ask you for a Labrador, you can't meet my needs with a Great Dane even though it's still a dog; I asked for a specific kind of dog.

Derived types are considered more specific than base types. Even though it doesn't, ArrayOfString() could have added more properties or methods. If something asks for ArrayOfString(), the compiler wants to be sure that whatever it gets has all of the attributes of ArrayOfString(). List(Of String) isn't guaranteed to meet these needs, so it's illegal.

So you need to use ArrayOfString. Since it derives from List(Of String), all you have to do is take the code you wrote to use List(Of String) and replace the type with ArrayOfString. I'd expect this to work:
Dim fieldNamesArray() As String = { "filenetdocid", "filenetsystemid", ... }
Dim fieldNames As New ArrayOfString()
The AddRange() method takes a collection of items and adds them all to the list. Alternatively, you could add each name individually:
Dim fieldNames As New ArrayOfString()
It's obviously a bit more tedious.

See if that works.
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Old 05-09-2011, 12:09 PM
sallymadeira sallymadeira is offline
Join Date: May 2011
Posts: 2

This worked like a charm - thank you so much.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..