none
SafeArray cannot be marshaled to this array type because it has either nonzero lower bounds or more than one dimension. RRS feed

  • Question

  • I am trying to call a VB6.0 COM method from C# but got the error message "SafeArray cannot be marshaled to this array type because it has either nonzero lower bounds or more than one dimension."

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

    VB code:

    Function prototype:

    Public Function Calculate(ByRef Amounts() As Currency) As Boolean

    Calculate = true

    End Function

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

    C# code:

    decimal[] amounts = new decimal[11];

    ok = Calculate(ref amounts);

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

    It seems like C# does not support dynamic array but here vb code is expecting that as a reference parameter. I have tried List as well but that doesn't work.

    Stacktrace: 

    System.StubHelpers.MngdSafeArrayMarshaler.ConvertSpaceToManaged(IntPtr pMarshalState, Object& pManagedHome, IntPtr pNativeHome)

    • Edited by Vivek9958 Wednesday, August 1, 2018 1:15 PM Added stack trace
    Wednesday, August 1, 2018 12:56 PM

All replies

  • I don't know what "Currency" is but you probably cannot use it in VB when calling the method that is expecting decimal. You might need to convert the decimal values from (and/or to) Currency.

    Look in the Object Browser and/or the Class View. What does it (or they) show for the Calculate method?



    Sam Hobbs
    SimpleSamples.Info

    Thursday, August 2, 2018 6:24 PM