none
Difference between ArrayList in VB from ArrayList in C#? RRS feed

  • Question

  • s there a difference  between the arraylist in visual basic and arraylist in C#?

    I had to convert some C# code to VB and there is a call I make in a third party api that requires me to pass in an arraylist.  When I do this in C# it works just fine, but when I do this in VB, I just get back a vaque exception from the api.  Any ideas?

    My code is extremely simple. 

    Dim thirdPartyApi As New ThirdPartyApi()
    Dim arrListEntryId As New ArrayList()
     arrListEntryId.Add("string1")
     arrListEntryId.Add("string2")
     arrListEntryId.Add("string3")
     arrListEntryId.Add("string4")
    thirdPartyApi.ApiCall(arrListEntryId)

    This exact same code works just fine in C#.  The only thing i could think of is that there is some non apparent difference in the ArrayList object in vb from C#.

    The exception I get is very vague and comes from the API.  All i get is, "ARException Occured".


    Thursday, April 12, 2012 3:30 PM

All replies

  • Hi,

    it could be the threading model used; 

    you could try setting the MTAThread attribute in the VB application.

    <MTAThread()> Public Sub main()

    See this post: http://bytes.com/topic/c-sharp/answers/269473-what-mtathread-why-doesnt-vb-have


    Regards, Nico

    Thursday, April 12, 2012 4:04 PM
  • Why post the same question in two different forums? I realize it could go in either but it ought not to go in both.

    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Thursday, April 12, 2012 4:08 PM
  • Well, for one, someone on the other thread suggested it.  Two, I always hear the arguments about which programmers are better. Let's see which one answers it first.  :)
    Thursday, April 12, 2012 4:23 PM
  • Thanks for the reply Nico.  In that link you posted, it states " VB.NET puts the STAThread attribute into the IL generated, you will not see it looking at the VB source itself".  So it does get set then it seems.
    Thursday, April 12, 2012 4:26 PM
  • hi,

    it sets STA not MTA!


    Regards, Nico

    Thursday, April 12, 2012 4:29 PM
  • The suggestion that you post in a different forum implies you posted in VSTO forum and suggested C# or VB, not both.

    You can of course quibble that the or is inclusive (as in logic) whereas it is normally taken as exclusive (in English) :)

    Point two is odd: first forum to answer = programmers in that language are better. Curious equation. :)


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Thursday, April 12, 2012 4:46 PM
  • Beto,

    Don't bother what David says, you have not posted it in the wrong forum a moderator has moved your question to that because it came probably first in his mind because you used first the word C#. You cannot post VB code in the C# forum. If that was possible I had already done that this morning. Beside that there is no Microsoft rule that you cannot post in different forums the same question. I even strongly advice it if your question can have different entry point of views. But that is not this case, it is a VB project which does not fit in your solution, not a C# project which does not fit in your VB solution.

    However, are you sure the reference to the Thirthparty Api is pointing to the same DLL, your code looks right.

    Trying to give you the idea it is true what I wrote I've created a combined VB C# project. 

    The VB Class in this contains this

    Public Class Class1
        Public Function GetArrayList() As ArrayList
            Dim arrListEntryId As New ArrayList()
            arrListEntryId.Add("string1")
            arrListEntryId.Add("string2")
            arrListEntryId.Add("string3")
            arrListEntryId.Add("string4")
            Return arrListEntryId
        End Function
    End Class

    The result is then this


    Success
    Cor



    Thursday, April 12, 2012 5:44 PM
  • Don't bother what David says

    And that from a man who often berates double posters and those who ask questions in an 'inappropriate' forum. ROFLMAO


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Thursday, April 12, 2012 5:57 PM
  • I tried this, but the issue was not fixed.
    Thursday, April 12, 2012 6:32 PM
  • Yes, I am positive I am pointing to the same dll in both applications.
    Thursday, April 12, 2012 6:32 PM
  • If it's a .net DLL, can you step through it to see what is going on? Alternatively reflect (using Reflector, for example) it to see if there's something obvious going on.

    The ArrayList is a .NET object: there's no difference between C# and VB. The error implies that it's not a .NET exception but an exception thrown by the maker of the DLL/API, but I couldn't be certain (the error is very vague - the .NET exceptions are generally not that vague).


    Stephen J Whiteley

    Thursday, April 12, 2012 6:48 PM
    Moderator
  • Have you tried asking the writer of the API? I'm guessing it's for Remedy from the error message, so that would be in the forum communities.bmc.com/communities/community/bmcdn/bmc_atrium_and_foundation_technologies/bmc_remedy_ar_system?view=discussions.

    --
    Andrew

    Thursday, April 12, 2012 6:49 PM
  • Thanks for the reply Nico.  In that link you posted, it states " VB.NET puts the STAThread attribute into the IL generated, you will not see it looking at the VB source itself".  So it does get set then it seems.

    again,

    it says STAThread, I say try it with MTAThread.

    <MTAThread()> Public Sub main()


    Regards, Nico

    Friday, April 13, 2012 6:52 AM
  • Hi Beto363,

    Welcome to the MSDN forum.

    I agree with the Bob’s suggestion in your another thread. This issue can be caused by the third party API. The exception showed in the API is too general for us to troubleshooting. So would you like to share more information about the error caused by third party API? As Andrew mentioned, connect to the writer or the website of the third party API to ask for help seems to be a suggestion for you.

    I’d like to share the thread in C# forum here, and it will make other members help you easier: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6b701109-3fd1-4913-bf9d-2dfbe89f9a7c/#a29c0889-34fa-4a59-91b4-7f1e99c4df64

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 16, 2012 5:33 AM
    Moderator