VB.net Class Not Registered Error - vb.net

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

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.

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

An unhandled exception of type 'System.AccessViolationException' occurred vb.net 2013

Imports Microsoft.Office.Interop
Imports System.IO
Imports Access
Public Class Form1
Dim AccessApplication As Microsoft.Office.Interop.Access.Application
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AccessApplication = New Access.Application()
If Not AccessApplication.Visible = True Then
AccessApplication.Visible = True
End If
AccessApplication.OpenCurrentDatabase("C:\POS\POS.lib", False)
End Sub
End Class
I'm trying to open "C:\POS\POS.lib" from vb.net 2013, but the error 'System.AccessViolationException' appear, I tried a lot of methods to fix it but didn't works :
the error appear on the line
AccessApplication.OpenCurrentDatabase("C:\POS\POS.lib", False)
This is the full error :
An unhandled exception of type 'System.AccessViolationException' occurred in PosStartup.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Here is the file logo:
Find the original file extension, and rename the file to have this extension before you open it, and rename it to the have "lib" extension, after you close it. Use System.Diagnostics.Process.Start to start Access in a new process. System knows to open Access, according to file extension:
If System.IO.File.Exists ("C:\POS\POS.lib") And Not System.IO.File.Exists Then ("C:\POS\POS.mdb") ' replace 'mdb' with the correct file extension
System.IO.File.Move("C:\POS\POS.lib", "C:\POS\POS.mdb")' replace 'mdb' with the correct file extension
System.Diagnostics.Process.Start("C:\POS\POS.mdb")' replace 'mdb' with the correct file extension
End If
If you have no need to manege Access from your VB.net app, remove all Office.Interop, and Access Namespaces objects, and use System.Diagnostics.Process.Start to start Access in a new process, and send the file to it as a parameter:
System.Diagnostics.Process.Start ("Access.exe", "C:\POS\POS.lib")
Rename Interop.DLL_Name.dll to DLL_Name.dll and reference it to project. Set Interop true.

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

Typecast exception from ShellBrowserWindow object to ShellFolderView object

Looking for help trying to figure out why this typecast is not working on my machine.
This code was provided as an answer to another question I had and it's not working for me. It works for the answer poster on their machine, but I'm get a an exception on the line trying to typecast from ShellBrowserWindow to ShellFolderView.
I am using Visual Studio Express 2013, running on Windows 7 Pro X64 Sp1. The target framework for the project is .Net Framework 4. I've added references to Microsoft Internet Controls and Microsoft Shell Controls and Automation and I've added the Imports statements for Shell32 and SHDocVw. DLL versions are as follows: shell32.dll = 6.1.7601.18517 and shdocvw.dll = 6.1.7601.1822 I'm not sure what I could be missing.
The code looks like this. (This code is in a form object)
Imports EdmLib
Imports Shell32
Imports SHDocVw
Public Class BlankForm
Private Sub BlankForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim bar As String() = GetExplorerSelectedFiles()
Exit Sub
'The rest of my program is below this line - I'm just trying to test this one function right now...
End Sub
'Uses the windows shell to get the files selected in explorer
Public Function GetExplorerSelectedFiles() As String()
Dim ExplorerFiles As New List(Of String)
Dim exShell As New Shell32.Shell
Dim SFV As Shell32.ShellFolderView
For Each window As SHDocVw.ShellBrowserWindow In DirectCast(exShell.Windows, SHDocVw.IShellWindows)
If (window.Document).GetType.Name <> "HTMLDocumentClass" Then
SFV = CType(window.Document, ShellFolderView) '<--This is where it fails!!
For Each fi As FolderItem In SFV.SelectedItems
ExplorerFiles.Add(fi.Path)
Next
End If
Next
Return ExplorerFiles.ToArray
End Function
End Class
The line SFV = CType(window.Document, ShellFolderView) results in the following message:
An unhandled exception of type 'System.InvalidCastException' occurred
in LaunchTemplateEPDM.exe
Additional information: Unable to cast COM object of type
'System.__ComObject' to interface type 'Shell32.ShellFolderView'. This
operation failed because the QueryInterface call on the COM component
for the interface with IID '{29EC8E6C-46D3-411F-BAAA-611A6C9CAC66}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I've taken a screenshot of a quickwatch on the window object. A quickwatch on the window.document object shows an error saying it's either undefined or inaccessible.
I ran the query Microsoft.VisualBasic.Information.TypeName(window.document) and it returns "IShellFolderViewDual3".
I fixed it.
Not sure why this happens on my system and not yours.
What I found was that GetType.Name always just returns "System.__ComObject", regardless of whether the object is of type ShellFolderView, HTMLDocumentClass or something else. So what was happening was no matter what the actual type of the object was, it was passing the <>"HTMLDocumentClass" test because it was always evaluating to "System.__ComObject". Then when we tried to run the CType function on an object that didn't implement the ShellFolderView interface, it would throw that exception.
I eventually stumbled upon this article which led me to experiment with the TypeName Function which seems to return the actual type, and so I ended up with the working code below:
Public Function GetExplorerSelectedFiles() As String()
Dim ExplorerFiles As New List(Of String)
Dim exShell As New Shell32.Shell
For Each window As SHDocVw.ShellBrowserWindow In DirectCast(exShell.Windows, SHDocVw.IShellWindows)
If TypeName(window.Document) Like "IShellFolderViewDual*" Then
For Each fi As FolderItem In DirectCast(window.Document, ShellFolderView).SelectedItems
ExplorerFiles.Add(fi.Path)
Next
End If
Next
Return ExplorerFiles.ToArray
End Function