0

I'm building a project to read servo drive parameters using an open source Modbus library called NModbus.

My VB.net project includes a reference to modbus.dll as well as log4net.dll. enter image description here

I can call methods inside the namespace modbus, using intellisense, and get no errors. But when I run this code inside the IDE...

Imports System.IO.Ports
Imports Modbus

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)         Handles MyBase.Load
    Dim MyPort1 As New SerialPort("Com1")

    MyPort1.BaudRate = 9600
    MyPort1.DataBits = 8
    MyPort1.Parity = Parity.None
    MyPort1.StopBits = StopBits.One
    MyPort1.Open()

    Dim myMB As Device.ModbusSerialMaster
    myMB = Device.ModbusSerialMaster.CreateAscii(MyPort1)

        Dim slaveId As Byte = 1
        Dim StartAddress As UShort = 100
        Dim registers() As UShort
        Dim NumberofRegisters As UShort = 5

        registers = myMB.ReadHoldingRegisters(slaveId, StartAddress, NumberofRegisters)



    End Sub
End Class

I get errors saying the types inside the Modbus namespace are undefined.

enter image description here

Why are the types defined while coding and I can use Intellisense to find my methods but they become undefined at runtime?

Killakeys
  • 93
  • 1
  • 3
  • 10
  • possible duplicate of [Visual Studio 2010 suddenly can't see namespace?](http://stackoverflow.com/questions/4880685/visual-studio-2010-suddenly-cant-see-namespace) – Hans Passant Nov 19 '13 at 22:25

2 Answers2

0

Probably due to the location of the DLL that you referenced. Since it is in bin\Debug, it may be getting overwritten whenever you recompile. Do you get the same behavior when you run the project as Release instead of Debug?

Douglas Barbin
  • 3,595
  • 2
  • 14
  • 34
  • I've tried putting the DLL in several locations, including a directory on the C drive and in the main project folder, and I get the same results. If I run it as Release I get the same error as well. – Killakeys Nov 19 '13 at 20:30
  • 1
    Did you try Clean/Rebuild in between runs? – Douglas Barbin Nov 19 '13 at 20:30
0

I changed the framework version from 4.0 to 3.5 and I no longer get the error. The dll was written several years ago and I assume there's something that doesn't run correctly in a newer framework.

Edit: Changing from 4.0 client profile to any regular framework works as well. The dll was referencing something the client profile didn't have. See the link at the top for more info on this bug in VS2010.

Killakeys
  • 93
  • 1
  • 3
  • 10
  • That's not it, using 3.5 assemblies in a 4.0 project is not a problem. – Hans Passant Nov 19 '13 at 22:25
  • I agree it shouldn't be, but I didn't change anything about the code or the references. I only created a new project in 3.5 framework and it worked. So yeah, that was it. – Killakeys Nov 20 '13 at 17:00
  • It least look at the link I gave you. – Hans Passant Nov 20 '13 at 17:03
  • Just saw the link...yes, changing from 4.0 client profile to regular 4.0 fixes the problem as well. So there's some namespace not included in the client profile that the dll was using? – Killakeys Nov 20 '13 at 17:36