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

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

Related

Error message "Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' "when running the published .exe

I've created a little VB.NET console application (using Visual Studio 2019 Commmunity Edition), that automatically downloads a file from the Internet.
The compiled .exe works just fine if I launch it from the Debug directory, inside my Project tree; it does not if I publish the application to a local folder; instead, I get the error message:
Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Here's the configuration I use to publish my app:
Apparently, this is the code generating the exception:
In Program Module:
Imports System
Imports Microsoft.VisualBasic
Imports Microsoft.Win32
Module Program
Sub Main(Args() As String)
(...)
End Sub
Sub Download_SpeedTest()
Dim ooklaWebSite As String
Dim html As String
ooklaWebSite = "https://www.speedtest.net/apps/cli"
Try
' Retrieve download link
Console.WriteLine("Getting download link from " & ooklaWebSite)
html = Get_WebPage(ooklaWebSite)
(...)
Catch ex As Exception
Console.WriteLine("An error occurred downloading SpeedTest utility. - " & ex.Message)
End Try
End Sub
In WebRequests Module:
Imports System.Net
Module WebRequests
Public Function Get_WebPage(WebURL As String) As String
Dim sourceString As String
Dim wc As New System.Net.WebClient
sourceString = wc.DownloadString(WebURL)
wc.Dispose()
Return sourceString
End Function
End Module
Here's an example of what I get when I run the published program from Windows Command Line:
Getting download link from https://www.speedtest.net/apps/cli
An error occurred downloading SpeedTest utility. - Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
As per I could see, the exception occurs as soon the function Get_WebPage is called (no code inside it is executed)
Any suggestion?
When you use Trim unused assemblies (in preview) it sometimes removes assemblies you actually need. You can either turn that off (bloating the file size) or for this particular error, you can add the following to your csproj file:
<ItemGroup>
<TrimmerRootAssembly Include="System.ComponentModel.EventBasedAsync" />
</ItemGroup>
This will make sure that System.ComponentModel.EventBasedAsync.dll (where System.ComponentModel.AsyncCompletedEventArgs is defined) is not trimmed from the final, self-contained binary.

Adding a list (T) property to a inherited panel class

I am vey new to programming with classes. I am setting up a new program and want to give it a new, good structure and want to work with classes. But, I am stuck now for two days....I have an object class inherited from a panel. I want to add a list with info to it. IT almost seems to work but the property window in my main form also shows the info collection editor but I get a error which I can not seem to get rid of.. What am I doing wrong.
The error mesage:
Severity Code Description Project File Line Suppression State
Error Invalid Resx file. Could not load type System.Collections.Generic.List`1[[KRE_Interface.Info, KRE Interface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 915, position 5. KRE Interface D:\Dropbox\Dropbox\kre\KRESoftware\Alma 1 Interface\20200820 KRE Interface V6\KRE Interface\frmMain.resx 915
My code of the class:
Public Class RbGroep
Inherits Panel
Private m_ItemsInfo As List(Of Info)
Public Sub New()
ItemsInfo() = New List(Of Info)
End Sub
Property ItemsInfo() As List(Of Info)
Get
Return m_ItemsInfo
End Get
Set(ByVal value As List(Of Info))
m_ItemsInfo = value
End Set
End Property
End Class
<Serializable()>
Public Class Info
Public Property Order As Integer
Public Property RbName As String
End Class
I have it working with the info of Sean Kelly. Thanks a lot. Only: in the class I try to access the list with information, to make some radio bullets.
For i = 0 To amount_of_rb
Dim newrb As New KRERadiobutton
newrb.Name = "rb" & i
newrb.Text = ItemsInfo(i).RbName
newrb.Tag = itemsinfo(i).Order
newrb.Tag = i
newrb.Location = New System.Drawing.Point(40, 20 * i)
AddHandler newrb.CheckedChanged, AddressOf RadioButton1_CheckedChanged
Me.Controls.Add(newrb)
Next
The line with the itemsinfo(i) give me errors. Anybody an idea how to adress these bvariables?
Add this line to the top of the .vb file containing your class:
Imports System.Collections.Generic

VS 2017: Reference required to assembly

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?

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...

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}"