473,472 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error: System.ArgumentException

Hi,

I've got some old code(VB6) which has been upgraded to VB.net.
In the old code, the undocumented function "VarPtr" is used. But in VB.net,
this function is no longer supported. I've searched the internet and found
some code withch should solve the problem.

This is the code:

Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned )
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function

But this code generates an error:

"An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll Additional information: Object contains non-primitive or
non-blittable data."

Since I'm a beginner, I was hoping that you could help me with this problem.

Thanks a lot!
Nov 20 '05 #1
3 6275
Richard,

VarPtr() is a very advanced piece of Visual Basic. It's not documented for
a reason (although I can't tell you what it is). The best I can think of
for you to do is to try to figure out what it's used for in the original
code and find some way to write new code that does the same thing.

Good luck!

Rob
Nov 20 '05 #2
"Richard de Beer" <richard at -geen zooi en spam enzo - moviat.nl>
schrieb

Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned )
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function

But this code generates an error:

"An unhandled exception of type 'System.ArgumentException' occurred
in mscorlib.dll Additional information: Object contains non-primitive
or non-blittable data."

Since I'm a beginner, I was hoping that you could help me with this
problem.


I think after calling GC.Free, the ret value gets invalid because the object
isn't pinned anymore. In addition, if the object is a value type, it
is destroyed when the functions returns
But, what are you trying to achieve?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "Richard de Beer" <richard at -geen zooi en spam enzo - moviat.nl> scripsit:
I've got some old code(VB6) which has been upgraded to VB.net.
In the old code, the undocumented function "VarPtr" is used. But in VB.net,
this function is no longer supported. I've searched the internet and found
some code withch should solve the problem.
Try to find a way around using this function. Why do you need it? What
exactly do you want to do? Maybe there is a much cleaner and better
solution.
This is the code:

Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle =
System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned )
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function
You must not free the 'GC' here, but that's not the main problem.
But this code generates an error:

"An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll Additional information: Object contains non-primitive or
non-blittable data."


Blittable and Non-Blittable Types
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconblittablenon-blittabletypes.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

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

Similar topics

4
by: | last post by:
Some time ago I installed VC# 2003, made a small generic project, compile with the allow unsafe flag and I get the error below: "error CS1577: Assembly generation failed -- Unexpected exception...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
17
by: ahaupt | last post by:
Hi all, I'm currently writing a load of class libraries, but not the main application iteslf. I want to provide some method for reporting errors back to the main application. At the moment...
7
by: Max | last post by:
I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code: Type oType =...
0
by: Daniel Rimmelzwaan | last post by:
Hello, I have another server error for you. I created this aspx page on my laptop, but the project files are all located on one of our servers. Everything builds, no code errors, but when I...
1
by: D A H | last post by:
I have gotten the same exception in multiple projects. I have solved the underlying problem. My question is if anyone knew of a setting that would cause this exception to be thrown. A...
1
by: serge calderara | last post by:
dear all, i am a bit confused on the way custom error are handling and occurs. First of all I have understand that customer error is used to defined more user friendly message to my end user and...
2
by: Dabbler | last post by:
I'm getting the following error when I try and insert a row using FormView, ObjectDataSource and stored procedure. The form has 40+ columns on it and I'm not sure how to diagnose where the problem...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
3
by: teo | last post by:
Mozilla error on postback and validation ----------- A Button causes a Listbox to desappear. If no item has been selected on the Listbox, all is OK. If one or more items are selected,
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.