473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

System.NullRefernceException Error

I am trying to use a DLL in my C# application.

The code that I have is:
..
..
..
[DllImport("atfuncs.dll")]
public static extern int AT_Device_Get_Status(int DeviceNumber);
..
..
..
serial = AT_Device_Get_Status(1);
It is at this point in the code that the following message appears on the
screnn:
Microsoft Development Environment
! An unhandled exception of type 'System.NullReferenceException' occurred in
Vaprel.exe

Additional information: Object reference not set to an instance of an object.

I don't know what I am doing wrong. I hope that someone in this group can
tell me what is wrong with my application.

John Vogel (lost in C# land)
Nov 16 '05 #1
1 1256
"=?Utf-8?B?TGFiZWwgb3ZlciBiaXRtYXAgZGlzcGxheQ==?="
<La********************@discussions.microsoft.co m> wrote in
news:84**********************************@microsof t.com:
I am trying to use a DLL in my C# application.

The code that I have is:
.
.
.
[DllImport("atfuncs.dll")]
public static extern int AT_Device_Get_Status(int DeviceNumber);
.
.
.
serial = AT_Device_Get_Status(1);
It is at this point in the code that the following message
appears on the screnn:
Microsoft Development Environment
! An unhandled exception of type 'System.NullReferenceException'
occurred in Vaprel.exe

Additional information: Object reference not set to an instance
of an object.

I don't know what I am doing wrong. I hope that someone in this
group can tell me what is wrong with my application.


John,

There are several possibilities to check:

- The DLL routine has a bug in it. Test the routine in the same
language as it was written in. For example, if the DLL was compiled
with C++, write a small C++ application to test the routine.

- The DLL was compiled in a language like C++ that performs "name
mangling" on the routine name. If this happens, the .Net P/Invoke
system won't be able to find AT_Device_Get_Status in the DLL. To
determine if this is the case, use a command line utility like
Microsoft's DUMPBIN or Borland's TDUMP to find out exactly what
method names are being exported from the DLL.

- Specify the CharSet and EntryPoint parameters in the DllImport
attribute:

[DllImport("atfuncs.dll", CharSet = CharSet.Auto,
EntryPoint = "AT_Device_Get_Status")]

See this link for more info:

http://msdn.microsoft.com/library/de...l=/library/en-
us/cpguide/html/cpconconsumingunmanageddllfunctions.asp

or

http://tinyurl.com/jc41
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DM | last post by:
Get this error when I try to run any ASP.NET web app from Visual Studio on my Win2K PC. Anyone seen this before ? BC32400: Class 'CLSID_CorSymWriter' could not be created: System Error...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
0
by: Matthias Kwiedor | last post by:
Hi! I want to create a WebBrowser Control at runtime. So i ported the "at start creation" of the Control to a new routine. Everything works fine, but i implement the BeforeNavigateFix and a...
8
by: A P | last post by:
Hi! I'm using ASP.Net Web Matrix on my PC and wanting to publish the files to our server. I try to copy (thru explorer) the files but it didn't work! I receive Runtime Error: Server Error...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
0
by: Kirk | last post by:
I'm trying to use a Web Service to be a Remoting client of an existing ..NET 2.0 server. But I get the following error when I try to use System.Runtime.Remoting.Channels.Http in my WebService. ...
0
by: nicomp | last post by:
I created a Web Service: I imported System.Data.SqlClient so I could access SQL server tables programmatically. The web service builds and deploys with no problems. When I try to add the...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.