Including c# program as a reference in a VB.NET app
Hi - I have a VB.NET app that reads a Vectornav GPS/IMU thru a USB port. The VB.Net program has been stable for several years, but has very sparse random failures where the heading data starts spinning. Vectornav has released a new SDK that includes a sample C# program that has access to many internal device registers and provides objects that may allow me to finally diagnose the root cause of these events.
I have set the C# app as a reference in my VB project, and can see the objects . . BUT
when I start a debug session with no change to the VB.Net code, the C# app starts, instead of the code in my Form1 Class.
Copilot diagnosed the problem being in the Application.Designer.vb where
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.WindowsApplication1.Form1
End Sub
needed to be
Me.MainForm = Global.GPS_IMU_Reader.Form1
There is a caution not to change the code in the application.designer.vb (and in fact the change to the code generates an error) but to make the change in the Project.GPS_Reader Properties application window.
This window is greyed-out - I have attached a screenshot of this page.
Re: Including c# program as a reference in a VB.NET app
Hi - I got distracted as the issues have become more complex - the GPSIMU app is an older Windows forms app maintained on the Aircraft Win10 computer using vs2017-vs2020, and when the projects were loaded to my dev office system under win11 and vs2020, it was migrated to .NET 4.8. It requires a memory file and I have a CreateMemoryFiles app of the same age that creates several memory files allowing different sensord to share data, and should display a startup form with a button to start. This has no build errors and app displays on the windows ribbon at the bottom of the screen but the form does not display. GitHub Chat has not been helpful . .
Re: Including c# program as a reference in a VB.NET app
Hi - Here is the vbproj from CreateMemoryFiles - I decided not to include the vbproj from GPS_IMU_Reader since . . .
The second line is a wonder - and got me looking at the vbproj file for a newer app PoolDataLoad which is radically different . . and included below - look for the string of dashes
I renamed the vbproj file and reopened VS2022 - no errors but no build capability - and I got error 0x80004002 - missing interface
I guess one solution would be to create a new project , copy all of the files but eventually I found
Re: Including c# program as a reference in a VB.NET app
Hi - and more entertainment - I found a MS posting which suggested using VS2019 as an intermediate step - for some reason I do not have the rights to download VS2019 from MS, so after searching all or our systems found a copy on an old win10 system, copied the files to a SSD and loaded to our current dev system. But there is no installer or setup.exe. What to do?
Re: Including c# program as a reference in a VB.NET app
And now really stumped ,. . Another MS suggestion was to recreate the project from scratch in VS2022 - so I created the Create Memory file app and copied the form and code - no errors until debug, the 2 error on file locked and no form display.
The I created a completely new app with 1 start button and 1 text box - now the form displays, but no display in the text box. Here is the code
Imports System.IO.MemoryMappedFiles
Imports System.Threading
Public Class Form1
Public WithEvents MEMSTimer As New System.Windows.Forms.Timer()
Dim LoopForever As Boolean = True
Dim GPSINS_Memory_File_Name As String = "GPSINSMemoryData"
Dim AHRS_Memory_File_Name As String = "AHRSMemoryData"
Dim Switch_Memory_File_Name As String = "SwitchMemoryData"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MMS = MemoryMappedFile.CreateNew(Switch_Memory_File_Name, 20, MemoryMappedFileAccess.ReadWrite)
Dim GPS = MemoryMappedFile.CreateNew(GPSINS_Memory_File_Name, 400, MemoryMappedFileAccess.ReadWrite)
Dim AHRS = MemoryMappedFile.CreateNew(AHRS_Memory_File_Name, 400, MemoryMappedFileAccess.ReadWrite)
Do Until LoopForever = False
'sleep for xx.0 Seconds
Call DisplayStatus
Thread.Sleep(100)
'Button1.BackColor = Color.GreenYellow
'Thread.Sleep(100)
Loop
End Sub
Private Sub DisplayStatus()
TextBox1.Clear()
TextBox1.Text = "Running"
TextBox1.BackColor = Color.Green
End Sub