How to obtain link actions and destinations (internal & external)?

Everything works OK now, except for one message I get from PDF.Net once
in a while.

  Message: The dictionary does not contain required key: Dest
  Conditional expression: false
  Function : PDFTRON::SDF::Dict::Get

I get this message for just a few documents. What I do is identifying
all internal links in a document and modify these so that they'll work
in the new, larger PDF.

The message originates from this logic:

   // Find all annotation links on the page.
   Obj annots = pPage.GetAnnots();
   if (annots != null)
    for (int i = 0; i < annots.Size(); i++)
      Obj dict = annots.GetAt(i);
      string subtype = dict.Get("Subtype").Value().GetName();
      if (subtype.Equals("Link"))
       // We got a link annotation.
       // Get the destination and it's offset.
       Destination dest = new Destination(dict.Get("Dest").Value());
       int index = dest.GetPage().GetIndex();
       // Get the Rect and use it as key.
       Rect key = new Rect(dict.Get("Rect").Value());
       pAnnotationTable.Add(key, index);
     catch (Exception e)
      System.Diagnostics.Debug.WriteLine("Annotation could not be
loaded. Details: " + e.Message);

The links that cause the exception seem to link to an external file.
My question is - can I somehow identify which links/annotations that do
not have the "Dest" dictionary entry so that I handle this in a better
way than I do presently?



The problem is that a desination may be stored via a link action.
Also both "Dest" and "A" entry are not absolutely requred to be present
in the dictionary.

You could use the following code instead:

int num_annots = page.GetNumAnnots();
for (int i=0; i<num_annots; ++i) {
  Annot annot = page.GetAnnot(i);
  if (annot.GetType() == Annot.Type.e_Link) {
    Action action = annot.GetLinkAction();
    if (action.GetType() == Action::e_GoTo) {
      int page_num = action.GetDest().GetPage().GetIndex();
    else if (action.GetType() == Action::e_GoToR) {
       // A remote/external goto action...
   Destination dest = action.GetDest();
  // Get the file specification dict
  Obj file_dict = action.GetSDFObj().Get("F").Value();
  FileSpec file_spec = new FileSpec(file_dict);
  String file_path = file_spec.GetFilePath();