C# - Adobe OLE JSObject - Value does not fall within the expected range

62 Views Asked by At

I'm switching over code from VB to C#, and with C# I'm getting a System.ArgumentException with the message Value does not fall within the expected range.

I know I must be missing something stupid simple, but as soon as I try to use any property or method of the jso, I get the exception.

AcroApp acroApp = new AcroApp();
AcroAVDoc acroAV = new AcroAVDoc();
if (acroAV.Open(LoadFilePath, string.Empty))
{
    AcroPDDoc acroPD = acroAV.GetPDDoc();
    dynamic jso = acroPD.GetJSObject();
    if (jso.NumFields > 0)
    {
        // Code never reaches here.
    }
}

I was originally late binding the other Adobe objects, and thought that might have been the issue. But, whether I use the type library or late bind, the code works fine up until the jso object.

With VB the code would look like this and works without any issues:

Dim acroApp As New AcroApp()
Dim acroAV As New AcroAVDoc()
If AcroAV.Open(LoadFilePath, String.Empty())
    Dim acroPD As AcroPDDoc = acroAV.GetPDDoc()
    Dim jso As Object = acroPD.GetJSObject()
    If jso.NumFields > 0 Then
        ' Code that does stuff
    End If
End If
0

There are 0 best solutions below