Error while connecting to AX using WPF ManagedHostControl, help?

Hello, I have a WPF control that I’m using as a ManagedHost control, and I added a Business Connector connection to display on the WPF control some records from AX 2012, when I run the ManagedHostControl from AX I get:

Exception has been thrown by the target of an invocation.

Any idea on what might be happening? the ManagedHost control was working fine beforing adding the Business Connector method, this is what I use to connect to AX, it works from Visual Studio, but not from DAX:

Axapta DynAx = new Axapta();

DynAx.Logon(null, null, null, null);

Thanks in advanced!

There is no reason to use Business Connector - that would allow you to communicate with AX from another application, but UI controls runs inside Dynamics AX client. You can use methods, properties and events for communication between AX and the control.

If you want to know why exactly your code failed, look first at what exception was thrown.

I may have not enough knowledge yet, I have a WPF control inside of a ManagedHost control in AX 2012, this WPF has a label, that I need to fill it with a query result from an ax table, as far as I know, I can’t access any of the controls in the WPF from DAX, that’s why I was using Business Connector, because I can’t find any other way to set into the label, the information I need from DAX tables.

How can I get the exception that was thrown? I only get the Exception has been thrown by the target of an invocation in the infolog in AX, because if I run it from VS, it works**.** Thanks in advanced for the help and the patience!

EDIT: I guess I got the idea, I can access to all the events and methods that I have into my WPF, from AX which is great; I have a timer in my WPF that was executing a statement to change the label value every 5 seconds, however the statement is being used in DAX now, is there something like a timer in DAX? thanks!

You may be interested in a tutorial that I wrote long time ago. It also shows how to use proxies of X++ object in your WPF control.

About the exception - I wouldn’t care about this particular exception, you definitely don’t want to use BC. But in general - you should catch the exception in X++ and examine the inner exception. You can use AifUtil::getClrErrorMessage() for this purpose. You can also attach Visual Studio debugger to the AX client to see the exception sooner and to use breakpoints in your .NET code.

About timers - you should still be able to use .NET timers, anyway AX offers setTimeOut() method for that.

I was able to do it based on Martin Dráb suggestion, I realized that you can access all the methods that are defined into WPF, from DAX, so I created a method to specifiy the label’s value, and called that method in the Timer method in DAX, so every 5 seconds the Timer executes a statement and write the result in the label through a method in WPF, thanks!

Is there any way to access MouseDown method of a specific element in the WPF from DAX? If I add the mouseDown event on DAX, it fires everytime you click on something that has the MouseDown event defined in the WPF, I just need to fire it when clicking on a specific element, any idea? for example I need to call only rectangle6_MouseDown, not any MouseDown event, thanks!