FIX: Tlbimp Does Not Support Retval Attribute on Parameters of Methods in a DISPINTERFACE (327118)
The information in this article applies to:
- Microsoft Windows .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft .NET Framework 1.0 SP2
This article was previously published under Q327118 SYMPTOMS When DISPINTERFACE has a retval attribute in the Interface Definition Language (IDL) file of the
Microsoft Component Object Model (COM) Server, and you use the Tlbimp utility
to import the COM Server that you want to use from Managed code, you receive an
"invalid argument exception".RESOLUTION The following workarounds change the COM Server or modify
the wrapper that is generated for the COM Server. Workaround 1 Modify the COM Server so that the retval is treated as a Byref argument. This causes the number of arguments that
are passed by the COM IDispatch call to the handler to change. The returned
value becomes the value that is returned in the last Byref parameter. However, this workaround causes the server to fail
with COM clients unless you have a way to differentiate the COM and the Managed
handlers and then handle both cases of invoking the handler through IDispatch.
Workaround 2 To modify the Managed wrapper that Tlbimp produces for
the COM Server by using Ildasm.exe and Ilasm.exe, follow these steps: - Use Ildasm.exe to extract the IL source code of the .dll
file or the .exe file. Then, modify the IL source code.
For example,
if the following is a section of the IL code before modification:
.method public hidebysig newslot abstract virtual
instance void Test([in] string marshal( bstr) Message,
[in] int32 Percent,
[out] int32& pretval) runtime managed preservesig internalcall
.method public virtual instance void
Invoke([in] string marshal( bstr) Message,
[in] int32 Percent,
[out] int32& pretval) runtime managed preservesig
then, notice how the void returns have been changed in the following
modified code:
.method public hidebysig newslot abstract virtual
instance int32 Test([in] string marshal( bstr) Message,
[in] int32 Percent) runtime managed preservesig internalcall
.method public virtual instance int32
Invoke([in] string marshal( bstr) Message,
[in] int32 Percent) runtime managed preservesig
- Use Ilasm.exe to compile the IL source code to a .dll file
or a .exe file again.
- Modify the IL source code.
For example, if the
following is a section of the IL code before modification:
.method public hidebysig newslot abstract virtual
instance void Test([in] string marshal( bstr) Message,
[in] int32 Percent,
[out] int32& pretval) runtime managed preservesig internalcall
.method public virtual instance void
Invoke([in] string marshal( bstr) Message,
[in] int32 Percent,
[out] int32& pretval) runtime managed preservesig
then, notice how the void returns have changed in the following
modified code:
.method public hidebysig newslot abstract virtual
instance int32 Test([in] string marshal( bstr) Message,
[in] int32 Percent) runtime managed preservesig internalcall
.method public virtual instance int32
Invoke([in] string marshal( bstr) Message,
[in] int32 Percent) runtime managed preservesig
- Use Ilasm.exe to compile the IL source code to a .dll file
or a .exe file again.
Workaround 3To work around this issue, Microsoft plans to introduce
a new switch for Tlbimp. Use the following switch (when available) with Tlbimp:
/transform:dispret
NOTE: This switch is currently not available in .NET Framework,
version 1.0 SP2. STATUS This bug
was corrected in .NET Framework (2003|1.1).
Modification Type: | Minor | Last Reviewed: | 5/28/2003 |
---|
Keywords: | kbfix kbCOMInterop kbpending kbprb KB327118 |
---|
|