BUG: You receive a "TargetParameterCountException" exception when you call the COM method with a Retval attribute (814721)
The information in this article applies to:
- Microsoft Visual C++ .NET (2003)
- Microsoft .NET Framework 1.1
SYMPTOMSWhen dispinterface has a retval attribute in the Interface Definition Language (IDL) file of the
Microsoft Component Object Model (COM) server, and when you use the Add
Reference tool to import the COM server that you want to use from Microsoft
Visual C++ .NET 2003 managed code, you may receive the following
exception: An unhandled exception of type
'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll
Additional information:
Invalid number of
parameters. CAUSE When you use the Add Reference tool in Visual C++ .NET
2003, the Type Library Importer (Tlbimp.exe) internally generates an interop
assembly. Tlbimp.exe does not run with the /transform:dispret option.WORKAROUNDTo work around this problem, create an interop assembly
manually, and then import the newly created assembly in your code. To create an
interop assembly, run Tlbimp.exe with the /transform:dispret command-line option. To do this, follow these steps:
- Remove the reference to the MyServer.DLL COM
component.
- Open a Microsoft Visual Studio .NET command
prompt.
- Type the following command, and then press ENTER:
tlbimp /transform:dispret YourCOMDLName
/out:Interop.YourCOMDLLName.dll - In Solution Explorer, right-click
Reference, and then click Add
Reference.
- On the .NET tab, click
Browse.
- Locate the interop .dll file that you created in step 3.
Click Open, and then click OK.
- In the ManagedClient.cpp file,
change the following code:
mysrv-> GetOffsetNum(100,&i); to this: i = mysrv->GetOffsetNum(100); - On the Debug menu, click
Start.
Note The .NET Framework 1.0 does not support the /transform:dispret command-line option for Ttlbimp.exe. STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 1/18/2006 |
---|
Keywords: | kbpending kberrmsg kbCOMInterop kbbug KB814721 kbAudDeveloper |
---|
|