Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

VB Late Binding Vs ASP - Using Interop Services

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christopher Pragash - 27 Aug 2003 04:04 GMT
Hello All,

I have a problem with ASP & VB 6 using an Interop Assembly . I marshal an
array in VB.NET, mark it as <MarshalAsAttribute(UnmanagedType.LPArray)>, and
I am able to retrieve the correct values in VB6 using Late Binding, not
predefining specific datatypes for the array. But ASP seems to have a
problem...and it crashes.

Following is the code sample in both VB and ASP

'All objects are declared as Variants...
'Lookup.LookupItems returns an Array marshled by VB.NET and marked as
<MarshalAsAttribute(UnmanagedType.LPArray)>

For Each objlookupItem In lookup.LookupItems
   txtoutput.Text = txtoutput.Text & objlookupItem.Description & Chr(13) &
Chr(10)
Next

In vb the above code returns the right values. In ASP returns:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'LookupItems'

Any ideas on why the problem in ASP and how I could resolve this?

Thanks in advance,

Chris
Mattias Sj?gren - 27 Aug 2003 12:37 GMT
Christopher,

Why do you use <MarshalAsAttribute(UnmanagedType.LPArray)>? SAFEARRAYs
are more OLE automation friendly.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Christopher Pragash - 27 Aug 2003 13:32 GMT
Mattias,

If I use the SafeArray attribute, VB does not understand the array, I get
errors irrespective of whether I use early binding or late binding. Any
ideas how I could marshal an array of objects from VB.NET To ASP??
Appreciate your response.

Thanks,
Chris

> Christopher,
>
> Why do you use <MarshalAsAttribute(UnmanagedType.LPArray)>? SAFEARRAYs
> are more OLE automation friendly.
>
> Mattias
Tim Golisch - 29 Aug 2003 20:57 GMT
One thing to keep in mind is that ASP can't handle typed arrays.  You
can only pass an array of variants.  Any other typed array will cause a
type mismatch error (even though ASP should have no problem converting
the elements of the array).
Laurent De Greef - 01 Sep 2003 16:36 GMT
You say that ASP can handle SAFEARRAY's of variants but the following C#
method :

public int SetStringArray([MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=(VarEnum.VT_VARIANT))] object[] stringArray)
{
return stringArray.Length;
}

fails when called from this VBScript code :

Dim dotNetArray
set dotNetArray = CreateObject("COMMarshalling.DotNetArray")
Dim strArray(3)
strArray(0) = "FirstString"
strArray(1) = "SecondString"
strArray(2) = "ThirdString"
Dim arCount
arCount = dotNetArray.SetStringArray(strArray)

I get the following error message :
Invalid procedure call or argument: 'SetStringArray'

According to me, the problem is that VBScript can only handle
SAFEARRAY's encapsuled into a VARIANT parameter as it works in C++ :
STDMETHOD (SetStringArray)(/*[in]*/VARIANT vArray)

I don't see how .NET can support this kind of parameter...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.