Invalid cast IPXV_DocumentViewsArea

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Invalid cast IPXV_DocumentViewsArea

Post by pHol »

Hi!

I am trying to (in a loop) go through all open IPXV_MainFrames to find the one (only have 1 document open per MainFrm) which has a document with a file name matching an inputted file name.
In my loop, I am doing the following

Code: Select all

Inst.MainFrm[i].View.DocViewsArea.ActiveDocView.Doc.CoreDoc.SrcInfo.ActualFileName.Equals(filePath)
If I have this in a try-catch statement it will throw an invalid cast exception every time. Tests I've made has led me to that it is the DocViewsArea call that throws the exception.
I am running SDK version 6.322.5 and this problem only came recently. From what I can see in the sdk documentation https://sdkhelp.pdf-xchange.com/vi ... V_MainView the MainView can access the ActiveDocView directly, but this has to be a new feature with verion 7 of the SDK, because I cannot access it directly from the View, only from the DocViewsArea.

Has enabling this feature on version 7 broken the possibility to access the DocViewsArea for older versions of the SDK? (It is still visible on in the documentation as you acn see in the link)

I hope I have explained my problem well enough and am looking forward to your answer

Kind regards,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Invalid cast IPXV_DocumentViewsArea

Post by Sasha - Tracker Dev Team »

Hello Philip,

If you did not update the dll, then there can be no problem with the SDK. That method was only added as a helping method - it won't change anything even in version 7 whatsoever. What I recommend you is to break that big chain into smaller parts and see what method exactly causes the exception.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Invalid cast IPXV_DocumentViewsArea

Post by pHol »

Hi Alex!

Here is a piece of code to prove that it is the DocViewsArea that produces the error

Code: Select all

try
{
    for (uint i = 0; i < _pxvInst.MainFrmCount; i++)
    {
    	Console.WriteLine(_pxvInst.MainFrmCount);
    	IPXV_MainFrame mainFrm = _pxvInst.MainFrm[i] as IPXV_MainFrame;
    	Console.WriteLine(mainFrm is IPXV_MainFrame);
    	IPXV_MainView view = mainFrm.View as IPXV_MainView;
    	Console.WriteLine(view is IPXV_MainView);
    	IPXV_DocumentViewsArea docViewsArea = view.DocViewsArea as IPXV_DocumentViewsArea;
    	Console.WriteLine(docViewsArea is IPXV_DocumentViewsArea);
    	IPXV_DocumentView documentView = view.DocViewsArea.ActiveDocView;
    	Console.WriteLine(documentView);Console.WriteLine();
    	
    	if (_pxvInst.MainFrm[i].View.DocViewsArea.ActiveDocView.Doc.CoreDoc.SrcInfo.ActualFileName.Equals(filePath))
    	{
    		return _pxvInst.MainFrm[i].View.DocViewsArea.ActiveDocView.Doc;
    	}
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
    Console.WriteLine();
}
and here is the output

Code: Select all

1
True
True
Exception thrown: 'System.InvalidCastException' in ***PROGRAM.exe***
Unable to cast COM object of type 'System.__ComObject' to interface type 'PDFXEdit.IPXV_DocumentViewsArea'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0647EED6-CE73-4167-8D0C-541654EADA08}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Is this of any help to you to be able to help me with this?

Cheers,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Invalid cast IPXV_DocumentViewsArea

Post by Sasha - Tracker Dev Team »

Hello Philip,

Everything works for me with your sample with the latest version of the SDK.
If you are using the older version, and this problem came recently (without the dll update) - it cannot be the problem with the dll itself. Probably you've added something in your code that causes this.
If you can provide a clean working sample project that recreates this (or for example use it in the FullDemo application) we can investigate further, because we cannot possibly know the background behind your project.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply