I have a problem on VB.NET service referencing a dll. I works well with Windows Form Application with the DLL on same folder. To be more specific the library has two files "library.dll" and "library.xml". The xml seem to have text that are required to the dll. When I remove the reference of DLL on Visual Studio, the service runs well. But when I add the library.dll to reference it doesn't work at all. Almost as referencing a dll in a windows service problem, and no solution there too.
I cannot enter even OnStart function so cannot log anything from my end. Here is what I get on event log:
Application: MyService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException
Stack:
at MyService.MyService..ctor()
at MyService.MyService.Main()
EDIT: My Code
Imports System.Threading
Imports FieldTalk
Imports System.IO
Imports System.Web.Script.Serialization
Public Class OPCModbusService
Dim is_stopping = False
Dim threadConfigurationChanged As Thread
Dim tags As New Dictionary(Of String, Tag)
Dim tags_group As New List(Of Dictionary(Of String, Object))
Dim tags_ReadTime As Date
Dim PLC_Address As New Dictionary(Of String, String)
Dim PLC_Address_ReadTime As Date
Dim MAC_address As String = ""
Dim MAC_Address_ReadTime As Date
Dim serializer As New JavaScriptSerializer()
Public mbusProtocol As New Dictionary(Of String, MbusTcpMasterProtocol)
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
If Not EventLog.SourceExists(EventLog1.Source) Then
EventLog.CreateEventSource(EventLog1.Source, EventLog1.Log)
End If
End Sub
Private Function openProtocol(address As String) As Boolean
Dim result As Integer
result = mbusProtocol(address).openProtocol(PLC_Address(address))
If (result <> BusProtocolErrors.FTALK_SUCCESS) Then
EventLog1.WriteEntry("Error opening protocol: " + BusProtocolErrors.getBusProtocolErrorText(result))
Return False
End If
Return True
End Function
Private Sub closeProtocol(address As String)
Try
mbusProtocol(address).closeProtocol()
Catch ex As Exception
End Try
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
' First we try to read configuration files
EventLog1.WriteEntry("We are reading")
' READ SOME Config
' READING CONFIG ENDS
' Then we start with threads
Try
threadConfigurationChanged = New Thread(AddressOf checkChangeInConfig)
Catch ex As Exception
EventLog1.WriteEntry("Cannot open read of configuration change thread!!!" & vbNewLine & ex.Message)
'Exit Sub
End Try
' INITIALIZING SERVICES ENDS
End Sub
Private Sub checkChangeInConfig()
While True
Dim macFileInfo As FileInfo = My.Computer.FileSystem.GetFileInfo(My.Application.Info.DirectoryPath + "\\config\\mac.txt")
Dim serverFileInfo As FileInfo = My.Computer.FileSystem.GetFileInfo(My.Application.Info.DirectoryPath + "\\config\\server.txt")
Dim tagFileInfo As FileInfo = My.Computer.FileSystem.GetFileInfo(My.Application.Info.DirectoryPath + "\\config\\tags.csv")
If macFileInfo.LastWriteTime > MAC_Address_ReadTime Then
reloadMac()
End If
If is_stopping Then Exit Sub
If serverFileInfo.LastWriteTime > PLC_Address_ReadTime Then
reloadServer()
End If
If is_stopping Then Exit Sub
If tagFileInfo.LastWriteTime > tags_ReadTime Then
reloadTags()
' We may need to take care of extra things here
End If
If is_stopping Then Exit Sub
For i = 0 To 10
Thread.Sleep(100)
If is_stopping Then Exit Sub
Next
End While
End Sub
Protected Overrides Sub OnStop()
' Yeah Yeah! We stop threads here
is_stopping = True
Try
threadConfigurationChanged.Abort()
Catch ex As Exception
End Try
End Sub
End Class
Please ignore those config\
files, those are working well without the import in library