Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:01:02+00:00 2026-06-13T12:01:02+00:00

This C# code is in a .NET 4.5 ComVisible assembly: C# Code [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid("22341123-9264-12AB-C1A4-B4F112014C31")]

  • 0

This C# code is in a .NET 4.5 ComVisible assembly:

C# Code

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("22341123-9264-12AB-C1A4-B4F112014C31")]
public interface IComExposed
{
    double[] DoubleArray { get; set; }
    object[] ObjectArray { get; set; }
    object PlainObject { get; set; }
    double ScalarDouble { get; set; }
}

[ClassInterface(ClassInterfaceType.None)]
[Guid("E4F27EA4-1932-2186-1234-111CF2722C42")]
[ProgId("ComExposed")]
public class ComExposed : IComExposed
{
    public double[] DoubleArray { get; set; }
    public object[] ObjectArray { get; set; }
    public object PlainObject { get; set; }
    public double ScalarDouble { get; set; }
}

From Excel 2010 32bit VBA, I’ve got the following behavior:

VBA Code

Dim VBArray(1 To 3) As Double
VBArray(1) = 1
VBArray(2) = 2
VBArray(3) = 3

Dim oComExposedEarlyBinding As New ComExposed

' Works
oComExposedEarlyBinding.ScalarDouble = 5

' Compile Error: Function or interface marked as restricted,
' or the function uses an Automation type not supported in Visual Basic
oComExposedEarlyBinding.DoubleArray = VBArray

' Compile Error: Function or interface marked as restricted,
' or the function uses an Automation type not supported in Visual Basic
oComExposedEarlyBinding.ObjectArray = VBArray

' Run-time error '424': Object required
oComExposedEarlyBinding.PlainObject = VBArray

' Run-time error '424': Object required
oComExposedEarlyBinding.PlainObject = 5

Dim oComExposedLateBinding As Variant
Set oComExposedLateBinding = New ComExposed
 
' Works
oComExposedLateBinding.ScalarDouble = 5

' Run-time error '5': Invalid procedure call or argument
oComExposedLateBinding.DoubleArray = VBArray

' Run-time error '13':  Type mismatch
oComExposedLateBinding.ObjectArray = VBArray
 
' Works
oComExposedLateBinding.PlainObject = VBArray

' Works
oComExposedLateBinding.PlainObject = 5

As you’ve noticed the PlainObject is working in late binding mode but, obviously, on the expense of losing typing and therefore losing auto complete (IntelliSense) in VBA which is not acceptable in my scenario.

The lines that I care for in my example are the following lines:

oComExposedEarlyBinding.DoubleArray = VBArray
oComExposedEarlyBinding.ObjectArray = VBArray
oComExposedEarlyBinding.PlainObject = VBArray

Getting any of the three lines above working would satisfy my need, so do you have any workaround or a solution that would make this work (note that I am not interested in passing the array as a parameter to a function)?

Update:
After submitting this issue to Microsoft’s support and waiting for almost three weeks. They confirmed that it is a bug and this is the KB: https://web.archive.org/web/20140531181434/http://support.microsoft.com/kb/327084 and the only workaround within C# is what is marked as the solution below.
However, I am able to confirm that this code works as expected if written in C++/CLI.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:01:03+00:00Added an answer on June 13, 2026 at 12:01 pm

    VBA array must be zero based and in c# use ref parameter, sample:

    Option Explicit
    
    Sub test()
        Dim VBArray(0 To 2) As Double
        VBArray(0) = 1
        VBArray(1) = 2
        VBArray(2) = 3
    
        Dim oComExposedEarlyBinding As New ComExposed
        oComExposedEarlyBinding.SetDoubleArray VBArray
    
    End Sub
    

    using System.Runtime.InteropServices;
    
    namespace COMVisibleTest
    {
        [InterfaceType(ComInterfaceType.InterfaceIsDual)]
        [Guid("22341123-9264-12AB-C1A4-B4F112014C31")]
        public interface IComExposed
        {
            void SetDoubleArray(ref double[] doubleArray);
        }
    
        [ClassInterface(ClassInterfaceType.None)]
        [Guid("E4F27EA4-1932-2186-1234-111CF2722C42")]
        [ProgId("ComExposed")]
        public class ComExposed : IComExposed
        {
            private double[] _doubleArray;
    
            public void SetDoubleArray(ref double[] doubleArray)
            {
                _doubleArray = doubleArray;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This C# code is in a .NET 4.5 ComVisible assembly: C# Code [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid(22341223-9264-12AB-C1B4-B4F112014C31)]
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I have this code : http://jsfiddle.net/VAkLn/6/ When i add a table : http://jsfiddle.net/VAkLn/7/ this
Could anyone please help me convert this code to vb.net, I have tried it
In this VB.NET code: Dim o as SomeClass Try o = new SomeClass 'call
I have this vb.net code ( but I think meaning code is equivalent for
I have this code in my ASP.NET application written in C# that is trying
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.