Unable to cast object of type  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Unable to cast object of type

Postby 2can2 » Wed Jan 27, 2016 1:06 pm

Hi,
I have had code added to display an extra field (Supplier name) to the Inventory Maintenance form, SOH, Transaction Detail tab. It works perfectly when Selecting Inventory, Maintenance then the stock item, SOH, Transaction detail!
However if you select Sales, Order Entry, it comes up with this error message ('Unable to cast object type' - I have attached the full message).
If you enter, it carries on fine BUT ANY form you open thereafter gives the same message!

[The extension doc has been deactivated and can no longer be displayed.]



I have a copy of this DB (Train) and exactly the same Plugins are loaded BUT I don't get this message??
I have attached the Plugin in Question - perhaps you can shed some light on this? Thanks.

Cheers
Attachments
Plugin Lonicera.Jiwa._2CAN.Rocky.Inventory DH01.xml
Inv SOH Plugin
(37.13 KiB) Downloaded 716 times
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: Unable to cast object of type  Topic is solved

Postby Mike.Sheen » Wed Jan 27, 2016 6:07 pm

I need to look into this further, but the short answer to solve your issue is to remove the Sales Quote form from the Forms tab of your plugin.

Longer answer:

It took me a bit to reproduce your error - it didn't occur for me when loading the Sales Order form - at first.

Then I looked at your plugin, and noticed in the Setup and SetupBeforeHandlers methods you're casting the passed in Jiwa form to the inventory maintenance form... I noticed then on the Forms tab you've got both the Inventory Maintenance Form and the Sales Quote Form there.

So, having seen that I tried to load the Sales Quote form and did get your error. Then I got the error whenever I tried to load ANY form - including the Sales Order form.

What's happening here is you've instructed the plugin framework to run your Setup and SetupBeforeHandlers methods whenever the Inventory Maintenance form OR the Sales Quote form is loaded by adding them to the Forms tab of your plugin.

In the Setup/SetupBeforeHandlers method you're not selectively casting the JiwaForm parameter - i.e.:

Code: Select all
Dim INVUI As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaInventoryUI.InventoryMaintenanceForm)


If you DO want the same plugin to do stuff for multiple different forms, you'll need to check the type before trying to cast - e.g.:

Code: Select all
If TypeOf JiwaForm Is JiwaInventoryUI.InventoryMaintenanceForm Then
     Dim INVUI As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaInventoryUI.InventoryMaintenanceForm)
ElseIf TypeOf JiwaForm Is JiwaSalesUI.SalesQuote.SalesQuoteEntryForm Then
     Dim QUOTEUI As JiwaSalesUI.SalesQuote.SalesQuoteEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesQuote.SalesQuoteEntryForm )
End If


BUT - you don't seem to do anything related to the quote form, so it is probably a simple case of that being added to the Form tab accidentally - so just removing it resolves the issue.

However - I want to look into this deeper, as you may have uncovered a bug - I don't understand why it works for the sales order form UNTIL you open the quote form (and get the error as I would expect) - and subsequent attempts to load anything other than inventory maintenance causes the same error - something screwy is going on.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Unable to cast object of type

Postby 2can2 » Thu Jan 28, 2016 10:28 am

Thanks Mike for your time and very informative answer!
Cheers
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 6 guests