dotnet / dotnet/vblang

Error/Warning BC42016 shows at compile-time but not in IDE (VS 2019/.NET Core 3.1)

Open
#488 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

This is something I stumbled upon while experimenting with late-binding access of COM objects via DynamicObject. (It would seem that COM object access is still a work-in-progress for .NET Core/.NET 5; hence my experimentation with DynamicObject). When Warning Configuration "Implicit conversion" is set to either "Error" or "Warn", the compiler flags the line with `AddressOf`, but never the IDE. Furthermore, the error/warning message doesn't make sense. E.g. in this case the issue it reports is "'Object' to 'String'", rather than perhaps "'Object' to 'Func(Of String, String)'"?

Snippet to reproduce, within a .NET Core Console app:

Imports System
Imports System.Console
Imports System.Dynamic
Imports System.Reflection

Module Program

Class DynaFoo
Inherits DynamicObject

Const progID = "Scripting.FileSystemObject"
Private ReadOnly instance As Object
Public Sub New()
instance = Activator.CreateInstance(Type.GetTypeFromProgID(progID, True))
End Sub

Public Overrides Function TryInvokeMember(binder As InvokeMemberBinder,
args As Object(),
ByRef result As Object) As Boolean
result = instance.GetType().InvokeMember(
binder.Name,
BindingFlags.InvokeMethod,
Type.DefaultBinder,
instance,
args)
Return True
End Function

End Class

Sub Main()
Dim o As Object = New DynaFoo()
Dim GetAbsolutePathName As Func(Of String, String) = AddressOf o.GetAbsolutePathName ' Compile-time error/warning here,
' yet IDE shows no issue, when Warning Configuration "Implicit conversion" is set to "Error"/"Warn".
' Error message is: false_BC42016\Program.vb(31,62): error BC42016: Implicit conversion from 'Object' to 'String'.
' Warning message is: false_BC42016\Program.vb(31,62): warning BC42016: Implicit conversion from 'Object' to 'String'.
Dim v = GetAbsolutePathName(".")
WriteLine($"v = {v}")
End Sub

End Module

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.