COM method error in C #, VB.NET, but works in Python

I'm having problems with the COM library I'm trying to use. I get an ArgumentException when I call a specific method and pass it null. This happens to me both in the C # project and in the VB.NET project (I call the method using Nothing), where I added a link to the library from the "COM" list in Visual Studio 2008. When I call the same method in Python, passing throughNoneThe method works as expected, without errors. I understand that Python interacts with the COM library through DCOM (and I have only the strangest idea of ​​what this means), while I can use the COM library directly when I reference it in my C # / projects VB.NET. Can something happen that will cause the parameter I pass to be confused before it gets into the COM library? I'm not sure what is going on here. I recently upgraded the COM library to a newer version, so I wondered if I could get version conflicts somewhere, throwing an exception. I deleted all the links to the COM library from my C # and VB.NET projects, deleted all the directories binand objadded the link again. This caused the Interop.MyCOMLibrary.dll file to appear inobjto have today's date instead of the older date I saw.

The only documentation I have in the COM library describes the method as follows:

Public Function AddItem( _
   ByVal ItemData As Variant _
) As Object

Now I am trying to find problems with the parameters Variant.

Edit: so for now Type.Missing, while other solutions work in order to pass me this method call without errors, an attempt to read certain properties of the string in the returned element from this method will result in:

System.Runtime.InteropServices.COMException: item does not exist.

This is another example where it worked in Python, but throws an exception in C #, so I can guess the oddities of DCOM-versus-COM more. Or maybe this is a threading issue, since I use MSTest for testing.

+3
4

, null . , " ", VT_EMPTY, VT_ERROR, VT_NULL. Type.Missing.

+3

Reflection.Missing Nothing/null?

+2

VB VB.NET , object .NET Variant . default(object), , new object() , - ! , , . null - new object()?

StackOverflow, , / . , Variant object .:)

+1

System.DBNull.Value ?

. , , AddItem null.

What I did was create a new VB project in a Visual Studio solution with one class with the only method Sharedthat called me, intending to pass Null from VB as an argument. The compiler complained that Null was no longer used, and suggested using it instead System.DBNull.Value. This did the trick, and, as I noticed later, System.DBNull.Valuealso worked in the C # project.

0
source

Source: https://habr.com/ru/post/1768485/


All Articles