Exception System.ArgumentException in dynamic object.

  • Thread starter Thread starter VictorLH
  • Start date Start date
V

VictorLH

Guest
Hello,

I have the following code:

class Program
{
static string strProgId = "MyAutomation.Document";
static dynamic pserver = null;
static void Main(string[] args)
{
try
{
Type tPserver = Type.GetTypeFromProgID(strProgId);
if (tPserver != null)
{
pserver = Activator.CreateInstance(tPserver);
}
pserver.About(null, 0);
pserver.OpenDataFile(IntPtr.Zero, true, "Test.dat");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
if (pserver != null)
{
pserver.FileExit();
}
}
}




It creates dynamic object for DCOM automation server and calls two methods on it. The first call (About) works fine. The second one (OpenDataFile) throws exception (System.ArgumentException) with message: "Could not convert argument 0 for call to OpenDataFile." Note that argument 0 in both calls is the same, but for some reason the first one works and the second does not. The exception is thrown before method is called. I tried all sorts of casting without success. Looks like some sort of bug in the dynamic class wrapper. I have attached exception details and the method definition from ODL file.

Exception details:

- e {"Could not convert argument 0 for call to OpenDataFile."} System.Exception {System.ArgumentException}
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HResult 0x80070057 int
HelpLink null string
+ InnerException null System.Exception
Message "Could not convert argument 0 for call to OpenDataFile." string
ParamName null string
Source "System.Dynamic" string
StackTrace " at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)\r\n at CallSite.Target(Closure , CallSite , ComObject , IntPtr , Boolean , String )\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)\r\n at CallSite.Target(Closure , CallSite , Object , IntPtr , Boolean , String )\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)\r\n at PurifyCOM.Program.Main(String[] args) in C:\\vlh\\Test\\MS.NET\\PurifyCOM\\Program.cs:line 23" string
+ TargetSite {Void CheckThrowException(Int32, System.Dynamic.ExcepInfo ByRef, UInt32, System.String)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+ Static members
+ Non-Public members


Method definition from ODL file:

[id(35)] boolean OpenDataFile(long hWnd, boolean bEmbed, BSTR* bsPfyFilePath );

Continue reading...
 
Back
Top