Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 5 VB Late bound variables unavailable at run time due to Public member 'Visible' on type 'Application' not found #66847

Closed
nkastratovic opened this issue Mar 18, 2022 · 3 comments

Comments

@nkastratovic
Copy link

nkastratovic commented Mar 18, 2022

Description

I'm running a C# application which calls a VB class called wrapper.vb, which uses MS Word objects. This code was tried and tested and worked fine with .NET 4.8 but now breaks in .NET 5.

I have a variable: Protected m_wdApp As Object

When the class is instantiated, it calls:

Reproduction Steps

    Public Sub New()
    m_wdApp = CreateObject("Word.Application")
    m_wdApp.Visible = False
    m_outputFormat = DOC_FORMAT
End Sub 

Expected behavior

Actual behavior

This throws the following exception
4c64q
:
Now the above would be all very fine and well, if I wasn't able to actually look at the contents of the m_wrdApp and see that yes, they are all intact and are all visible in my watch Windows
r09tg
.
Using the Immediate window, attempting to access any of these attributes from the Word object throws an error (as you'd expect).

However, if I ask VS to "add a watch" to one of the attributes, for instance this "Visible" which we currently need, it comes out with this convoluted watch name
Ip3az
:

Regression?

I should note that all of this worked fine before upgrading to .NET 5, so I'm wondering if this is either a bug or there are some new rules for dealing with late bound variables.

Known Workarounds

No response

Configuration

VB .NET 5
Windows 10
x64

Other information

No response

@ghost
Copy link

ghost commented Mar 18, 2022

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I'm running a C# application which calls a VB class called wrapper.vb, which uses MS Word objects. This code was tried and tested and worked fine with .NET 4.8 but now breaks in .NET 5.

I have a variable: Protected m_wdApp As Object

When the class is instantiated, it calls:

Reproduction Steps

    Public Sub New()
    m_wdApp = CreateObject("Word.Application")
    m_wdApp.Visible = False
    m_outputFormat = DOC_FORMAT
End Sub 

Expected behavior

yes

Actual behavior

This throws the following exception
4c64q
:
Now the above would be all very fine and well, if I wasn't able to actually look at the contents of the m_wrdApp and see that yes, they are all intact and are all visible in my watch Windows
r09tg
.
Using the Immediate window, attempting to access any of these attributes from the Word object throws an error (as you'd expect).

However, if I ask VS to "add a watch" to one of the attributes, for instance this "Visible" which we currently need, it comes out with this convoluted watch name
Ip3az
:

Regression?

I should note that all of this worked fine before upgrading to .NET 5, so I'm wondering if this is either a bug or there are some new rules for dealing with late bound variables.

Known Workarounds

No response

Configuration

VB .NET 5
Windows 10
x64

Other information

No response

Author: nkastratovic
Assignees: -
Labels:

area-Microsoft.VisualBasic

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

@nkastratovic Moving from .NET Framework 4.8 to .NET 5 represents a major shift. The .NET 5 release represents a continuation of the .NET Core work started in early 2014 and has been a completely separate code base since then. Basic support for COM interop was added in .NET Core 3.0. However, some work remained and has been added back across the .NET Core 3.1 and .NET 5+ releases. I believe you may be hitting issues that weren't addressed until .NET 6, some of the dynamic/late-bound code scenarios in particular. Could you please try .NET 6 and see if you still observe the same behavior?

@AaronRobinsonMSFT AaronRobinsonMSFT added the untriaged New issue has not been triaged by the area owner label Mar 19, 2022
@nkastratovic
Copy link
Author

We should be using Interop.

We added Imports Microsoft.Office.Interop

We also changed

Protected m_wdApp As Object
to...

Protected m_wdApp As Word.Application
And needed to update variables such as

Dim inlineShape As Object
to

Dim inlineShape As Word.InlineShape
and...

For Each hl As Object In m_wdApp.ActiveDocument.Hyperlinks
to:

For Each hl As Word.Hyperlink In m_wdApp.ActiveDocument.Hyperlinks

@ghost ghost locked as resolved and limited conversation to collaborators Apr 21, 2022
@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants