error when call the unmanaged resouce functions from c#.net core dll into vb.netcore windows application

raj reddy 1 Reputation point
2022-06-10T02:34:59.15+00:00

Hi Team,

I got Issues when i call the unmanaged resources functions from c#.net core dll into vb.netcore windows application and automatically stops the execution of program when hit that function

Please below is my code

Dll Unmanaged function

--------------------------------------

[UnmanagedCallersOnlyAttribute]
public static void OpenGrpcConnectionNE(IntPtr ptrAddress)
{
try
{
string strAddress = Marshal.PtrToStringAnsi(ptrAddress);

            channel = GrpcChannel.ForAddress(strAddress);  
        }  
        catch (Exception ex)  
        {  
            WriteLog("ExceptionLog.txt", "OpenGrpcConnectionNE: " + ex.Message);  
        }  
    }  

vb.netcore windows code below to call dll

-------------------------------------------------------------

<DllImport("ClassLibNE.dll")>
Private Shared Sub OpenGrpcConnectionNE(ByVal ptrAddress As IntPtr)
End Sub

Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Try
If String.IsNullOrEmpty(txtAddress.Text.Trim()) Then
MessageBox.Show("Please enter address")
Else
Dim strRequest As String = String.Format("CassDensity={0},CassId={1},EmpId={2},ExtProdId={3},JulianDate={4},LotId={5},Motherlot={6},ProdId={7},QuantityIn={8}, QuantityOut={9},Sah={10},SputId={11},SputId2={12},TestcellId={13},TestcellOper={14},TestcellTime={15}", txtCassDensity.Text.Trim(), txtContainerNumber.Text.Trim(), txtEmployeeID.Text.Trim(), txtExtProduct.Text.Trim(), txtJulianDate.Text.Trim(), txtLotNumber.Text.Trim(), txtMotherLot.Text.Trim(), txtProduct.Text.Trim(), txtQuantityIn.Text.Trim(), txtQuantityOut.Text.Trim(), txtSAH.Text.Trim(), txtSputterResource.Text.Trim(), txtFlexiSputter.Text.Trim(), txtTestcellResource.Text.Trim(), txtOperation.Text.Trim(), txtTestcellTime.Text.Trim())

            Dim ptrAddress As IntPtr = Marshal.StringToHGlobalAnsi(txtAddress.Text.Trim())  
            Dim ptrRequest As IntPtr = Marshal.StringToHGlobalAnsi(strRequest)  
            'Dim cls As Class1 = New Class1  

            OpenGrpcConnectionNE(ptrAddress)  

            Dim ptrResponse As IntPtr = LotStatusInquiryNE(ptrRequest)  
            Dim strResponse As String = Marshal.PtrToStringAnsi(ptrResponse)  

End If
End If
Catch ex As Exception
' Show the exception's message.
MessageBox.Show(ex.Message)
End Try
End Sub

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
291 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,007 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: The period of time during which a program is being executed in a computer.
957 questions
.NET Standard
.NET Standard
A formal specification of .NET APIs that are available on multiple .NET implementations.
484 questions
{count} votes