run-time error 'System.TypeInitializationException'

177 views
Skip to first unread message

micr...@micromax.pl

unread,
May 29, 2007, 6:24:44 PM5/29/07
to NModbus
Hi
I tried to write sample in VC++ 2005 and after compilation I received
the following run-time error:

"An unhandled exception of type 'System.TypeInitializationException'
occurred in Modbus.dll
Additional information: The type initializer for
'Modbus.IO.ModbusRtuTransport' threw an exception."
Here is code (
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using "Modbus.dll"
#using "log4net.dll"

using namespace System;
using namespace System::IO::Ports;
using namespace Modbus::Device;


int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
SerialPort^ port = gcnew SerialPort("COM2");

port->BaudRate = 9600;
port->DataBits = 8;
port->Parity = System::IO::Ports::Parity::None;
port->StopBits = System::IO::Ports::StopBits::One;
port->Open();

// create modbus master
ModbusSerialMaster^ master = ModbusSerialMaster::CreateRtu(port);

unsigned char slaveID = 1;
unsigned short startAddress = 5;
unsigned short numRegisters = 1;

unsigned short register5 = master->ReadHoldingRegisters(slaveID,
startAddress, numRegisters)[0];
Console::WriteLine(String::Format("Register 5: {0}", register5));
Console::WriteLine("Press any key to exit.");
Console::ReadKey();

// return 0;
}

I registered Modbus.dll by 'regasm'.
Can anyone help me?

jackrz

Diogonb

unread,
Jun 26, 2007, 4:33:44 PM6/26/07
to NModbus

I receive this same error and it was because I forgot to copy the
"log4net.dll" to the same directory of the aplication. See if you have
registered it right.


On May 29, 7:24 pm, micro...@micromax.pl wrote:
> Hi
> I tried to write sample in VC++ 2005 and after compilation I received
> the following run-time error:
>

> "An unhandledexceptionof type 'System.TypeInitializationException'

Reply all
Reply to author
Forward
0 new messages