VS 2017: Reference required to assembly - vb.net

It seems, that in VS 2017, a project using an overloaded method, needs to have references to all the types of all the overloaded methods, even if it uses just one of these overloaded methods.
For example, consider ClassLibrary1 with the classes ServicedComponent1 and SharedMethods:
Public Class ServicedComponent1
Inherits EnterpriseServices.ServicedComponent
End Class
Public Class SharedMethods
Public Shared Sub DoDispose(ByRef obj As Messaging.Message)
obj.Dispose()
End Sub
Public Shared Sub DoDispose(ByRef obj As EnterpriseServices.ServicedComponent)
obj.Dispose()
End Sub
End Class
In ConsoleApp1, which references ClassLibrary1 and System.EnterpriseServices, I have the following Module:
Module Module1
Sub Main()
Dim obj1 = New ClassLibrary1.ServicedComponent1
ClassLibrary1.SharedMethods.DoDispose(obj1)
End Sub
End Module
When I try to compile ClassLibrary1, I get the following error:
1>C:\temp\TestReferences\ConsoleApp1\Module1.vb(5,9): error BC30652: Reference required to assembly 'System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the type 'Message'. Add one to your project.
In VS 2010, ConsoleApp1 compiles successfully, because I do not use the first overloaded method that uses System.Messaging.Message. I only use System.EnterpriseServices.ServicedComponent for which I have a reference in ConsoleApp1. It seems, that VS 2010 is smarter than VS 2017, because it finds out that the reference to System.Messaging is not needed.
Why does VS 2017 require a reference to System.Messaging?
Is there an option, so that VS 2017 behaves in this respect as VS 2010?

Related

VS2019 class constructor with different signatures requires all signatures types be included as references by calling program

This has been reported via VS2019 feedback mechanism, but I need a solution quicker. Code snippets are below. Apologies for not knowing how to format this better.
Library class has three constructors, the calling test program in same solution which is .NET V4, is required to have a reference to System.Web when it is not needed. When System.Web is referenced and imported, problem occurs that VS2019 V16.6 thinks Newtonsoft.Json V9.0.1 is being referenced. This is on the critical path for a WS2008R2 (VS2010) to WS2019 (VS2019) migration. Problem not seen on WS2012 or WS2016, both with VS2010.
Severity Code Description Project File Line Suppression State
Warning The primary reference “C:\Users\grollman\Documents\Visual Studio 2019\Projects\WriteToQB\WriteToQB\bin\Debug\WriteToQB.dll” could not be resolved because it has an indirect dependency on the assembly “Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed” which was built against the “.NETFramework,Version=v4.5” framework. This is a higher version than the currently targeted framework “.NETFramework,Version=v4.0”. TestWriteToQB C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2081
Library class
Public Sub New()
m_Page = Nothing
dicWinFormsCache = New Dictionary(Of String, String)(StringComparer.OrdinalIgnoreCase)
InitCRCTable()
End Sub
Public Sub New(objPage As System.Web.UI.Page)
m_Page = objPage
InitCRCTable()
End Sub
Public Sub New(dicIn As Dictionary(Of String, String))
dicWinFormsCache = dicIn
InitCRCTable()
End Sub
calling test program error statement:
Severity Code Description Project File Line Suppression State
Error BC30652 Reference required to assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ containing the type ‘Page’. Add one to your project. WriteToQB C:\Users\grollman\Documents\Visual Studio 2019\Projects\WriteToQB\WriteToQB\clsWriteToQB.vb 25 Active
calling test program
Dim m_objclsDataFunctions As clsDataFunctions.clsDataFunctions
Public dicSettings As New Dictionary(Of String, String)
Private ReadOnly Property objclsDataFunctions As clsDataFunctions.clsDataFunctions
Get
If IsNothing(m_objclsDataFunctions) Then
'Dim applicationCache As System.Web.Caching.Cache = System.Web.HttpRuntime.Cache
m_objclsDataFunctions = New clsDataFunctions.clsDataFunctions(dicSettings)
End If
Return m_objclsDataFunctions
End Get
End Property

COM DLL method using referenced enumeration

I've created a VB.NET application in VS2015 using x86 compiler and .net target framework 4.5.2
I created a RCW for a COM dll written in VB6 using tlbimp, called "NETLib.dll" and added this interop as a reference to my project.
This COM dll holds the following method:
Function DoSomething(sData As String, iData As Integer, eData As RefLib.enumDat) As Integer
within the class claSomeClass.
My issue: As soon as I use this method in my VB.NET project like the following
Public Class MyClass
Private oNetLibClass As NetLib.claSomeClass
Sub New()
oNetLibClass = New NetLib.claSomeClass
Dim eVal = RefLib.enumDat.Foo
Dim lReturn = oNetLibClass.DoSomething("DoIt", 1, eVal)
End Sub
End Class
I get an error:
BC30652: Reference required to assembly 'RefLib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null' containing the type 'enumDat'.
Add one to your project.
for the line Dim lReturn = oNetLibClass.DoSomething("DoIt", 1, eVal) even though I added RefLib (which also is a COM dll) as an interop to my VB.NET project.
Why do I get this error?
P.S: The line Dim eVal = RefLib.enumDat.Foo is not throwing any error, so I assumed the reference was added correctly...

How can SQLAnywhere's "external CLR" access a System Process

In need of an extension in SQLAnywhere (16) to access some DOS functions on the server where the DB is running, I tried :
A first code for a DLL to be called from Sybase
________! SAExternal.vb !____________
Imports System.Diagnostics
Public Class SAExternal
Public Shared Function getDone()
Dim myProcess As Process = System.Diagnostics.Process.Start("notePad.exe", "C:\data\CLR\zTest.txt")
myProcess.WaitForExit()
myProcess.Close()
getDone = "OK"
End Function
End Class
compiled using :
vbc.exe /t:library /out:SAExt.dll SAExternal.vb
Follows some code to test my DLL
_________! SAMain.vb !______________
Module SAMain
Sub Main()
Dim obj as New SAExternal()
MsgBox("Test SAMain " & obj.getDone())
End Sub
End Module
compiled using : vbc.exe /t:winexe /r:SAExt.dll SAMain.vb
SAMain.exe opens correctly notepad.exe, waits until I close it, and comes with the message "Test SAMain OK"
In SQLAnywhere, I coded :
CREATE FUNCTION getDone()
RETURNS LONG VARCHAR
EXTERNAL NAME 'C:\data\CLR\SAExternal\SAExt.dll::SAExternal.getDone() string'
LANGUAGE CLR
Calling the function by "Select getDone()" returns an error :
"Impossible to load the file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=........' or one of it's denpendencies..."
If I take out the Process part of the SAExternal module:
Public Class SAExternal
Public Shared Function getDone()
getDone = "OK"
End Function
End Class
my function gives me the correct answer ("OK")
For test purposes, I leaved all these files in the same directory as my Database file, including .vb and .dll .
I've searched the web for days to understand what I did wrong, and can't find what I missed.
Could somebody help me ?
try
CREATE FUNCTION getDone() RETURNS LONG VARCHAR
EXTERNAL NAME 'C:\data\CLR\SAExternal\SAExt.dll::SAExternal.getDone() *out* string'
LANGUAGE CLR
Please notice the addition of the out option before string

Reference to non-shared member requires an object reference

I am writing macro for Visual Studio in VB:
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic
Public Class C
Implements VisualCommanderExt.ICommand
Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
FileNamesExample()
End Sub
Sub FileNamesExample()
Dim proj As Project
Dim projitems As ProjectItems
' Reference the current solution and its projects and project items.
proj = DTE.ActiveSolutionProjects(0)
projitems = proj.ProjectItems
' List the file name associated with the first project item.
MsgBox(projitems.Item(1).FileNames(1))
End Sub
End Class
And I got this after compilation:
Error (17,0): error BC30469: Reference to a non-shared member requires an object reference.
Have you any ideas what is wrong? I didn't develop in VB earlier and I just need instant help.
DTE is a type, as well as what you've given to the name of a parameter in your Run method. When used in this line:
proj = DTE.ActiveSolutionProjects(0)
It's using the type, rather than an instance of an object. You need to pass through the variable into your method:
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic
Public Class C
Implements VisualCommanderExt.ICommand
Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
FileNamesExample(DTE)
End Sub
Sub FileNamesExample(DTE As EnvDTE80.DTE2)
Dim proj As Project
Dim projitems As ProjectItems
' Reference the current solution and its projects and project items.
proj = DTE.ActiveSolutionProjects(0)
projitems = proj.ProjectItems
' List the file name associated with the first project item.
MsgBox(projitems.Item(1).FileNames(1))
End Sub
End Class

VB.net Class Not Registered Error

I'm in the process of writing a VB application but whenever I run the application I get the error listed below:
"An error occurred creating the form. See Exception.InnerException for details. The error is: Retrieving the COM class factory for component with CLSID {11219420-1768-11D1-95BE-00609797EA4F} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
I have tried registering the shell32.dll file, I have looked in the registry for the entry {11219420-1768-11D1-95BE-00609797EA4F} but it does not exist, and I have tried compiling this application for x86.
Imports Shell32
Imports System.IO
Public Class frmIconChanger
Dim sh As ShellLinkObject = New ShellLinkObject
Private Sub btnBackupAndChange_Click(sender As Object, e As EventArgs) Handles btnBackupAndChange.Click
For Each desktopIcon In My.Computer.FileSystem.GetFiles("C:\Users\" + getUserName().ToString + "\Desktop")
Dim fileExtension As String = Path.GetExtension(desktopIcon)
If (fileExtension = ".lnk") Then
MsgBox(sh.GetIconLocation(desktopIcon).ToString)
End If
Next
End Sub
Private Function getUserName() As String
Return System.Environment.UserName.Trim
End Function
End Class
Other information: I am on a Windows 7 64-bit machine. I have .Net 4.0 and previous versions and am working in Visual Studio 2012. Also I have shell32.dll added as a reference in my project. Any help resolving this issue would be much appreciated.
Thanks.
Refer to this link Creating Links. Take a look at the "C" code and look for constants
CLSID_ShellLink
IID_IShellLink
Those are the values you need for the class and interface.
This other link is useful: IShellLink interface
This should be the GUIDs you need:
CLSID := "{00021401-0000-0000-C000-000000000046}"
IID := "{000214F9-0000-0000-C000-000000000046}"