title: Can I override 'ComVisible(false), on inherited objects? (vb)
body: <p>apologies for my probably naive question here but I'm stuck on an issue I seem to be coming up against.</p>
  <p>Currently...</p>
  <p>I have a class, that inherits a 'Button' control (specifically the Button of the Guna framework (nuget)),</p>
  <p>this class gets passed to an array and then to a Scriptcontrol class and added to a VBscript (courtesy of .AddObject)</p>
  <p>For the script control to see the objects I seem to need to have Comvisible set as true- I have set this in the assembly info. and tried declaring it in each class.</p>
  <p>I can add the objects to the script ok, however, the problem occurs when I try to do anything with the object in the script.  The script says &quot;<strong>operation is not legal in the current state&quot;</strong>  It seems to point to ComVisible being false in dependant classes or objects. - but I could be wrong, I probably am.</p>
  <p>If I remove the inherited framework, and inherit a standard VS control (i.e. Button), then the script works as it should, and I can access objects in the script.</p>
  <p>Am I able to inherit a control and override its Comvisible attribute / force it? Is there a better way of doing that? or, am I probably adding the objects to the script wrong?</p>
  <p>I am using VS2019 - vb - winforms -.net4.8</p>
  <p>Thanks, in advance.</p>
  <pre><code>Imports System.Runtime.InteropServices
  
      &lt;ComVisible(True)&gt;
      Public Class Form1
      
      Public ObjectArray(10) As MyButton
  
  
      Dim SCRIPT1 As New ScriptController
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Init()
      End Sub
  
  
      Sub Init()
          Dim i As Integer
  
  
          For i = 0 To 9
              ObjectArray(i) = New MyButton
              ObjectArray(i).Property1 = i.ToString
          Next i
  
          SCRIPT1.DoScript(ObjectArray)
  
      End Sub
  
  
  End Class
  
  
  Public Class ScriptController
      Inherits MSScriptControl.ScriptControlClass
  
      Dim c As New Collection
  
      Public ScriptToRun As String = (&quot; Sub Main ()                                   &quot; &amp; vbCrLf &amp;
                                      &quot;                                               &quot; &amp; vbCrLf &amp;
                                      &quot; Objects1(2).Property1 = &quot;&quot;Howdy&quot;&quot;            &quot; &amp; vbCrLf &amp;
                                      &quot;  msgbox Objects1(2).Property1                 &quot; &amp; vbCrLf &amp;
                                      &quot;                                               &quot; &amp; vbCrLf &amp;
                                      &quot;End Sub&quot;)
  
  
      Public Sub DoScript(ObjArr() As Object)
          Dim s As New MSScriptControl.ScriptControlClass
          Dim i As Integer
  
  
          c.Clear()
  
          For i = 1 To 10
              c.Add(ObjArr(i - 1))
          Next i
  
          s.Language = &quot;vbscript&quot;
          s.AllowUI = True
  
          s.AddObject(&quot;Objects1&quot;, c, True)
  
          s.AddCode(ScriptToRun)
  
          s.Run(&quot;Main&quot;)
  
          s.Reset()
  
      End Sub
  
  End Class
  
  
  Public Class MyButton
  
      ' Inherits Guna.UI2.WinForms.Guna2Button
  
      ' // Changing between these switches the problem //
  
        Inherits Button
  
       
        Public Property Property1 As String
  
  End Class
  </code></pre>