With all the amazing connectors MuleSoft provides, I was happily surprised to see MuleSoft also has Visual Studio plugin which works with the mule dotnet connector. What this means is, not only can you use your most complex .Net code in Mule flow but you can now also hit a break point and debug the .Net code when your mule flow is running.
Assuming you are already familiar with the workings of Mule dotnet connector, Debuging dot net code from mule application can be completed in just 3 steps:
Step1: Downloading extension
Download Anypoint extensions for visual studio. This works with Visual Studio 2015 but the support for 2017 is not yet out. So if you have 2017 already, you may want to download and install Visual Studio 2015 Community Edition.
You can verify that the anypoint extensions for visual studio was successfully installed by right clicking on any visual studio project and noticing the Mule Project Settings on the context menu:
Step2: Setup you Mule workspace and select project
Clicking on the Mule project settings should open up dialog for you to to select your mule workspace and mule project you want to debug
Step3: Start/Run .net code from visual studio and mule application from anypoint studio
Once you are done configuring the workspace and selecting project, you can start the dot net code and see below message indicating that visual studio is waiting for Anypoint studio to start up
Once you run mule project in anypoint studio, it will be attached to visual studio and from there on whenever the dot net connector code is invoked, the debugger break point on visual studio will be hit and the execution will wait for user to continue.
One more thing which I thought was pretty cool is that you can run the mule project in anypoint studio either in Debug mode or Non-Debug(Run) mode and still the debug dot net code in visual studio. This not only allows you to debug both Mule and dot net code sequentially step by step but also gives option to skip debugging of Mule code if you are only interested in debugging dot net code.
Added benefit with anypoint extensions for visual studio
While selecting the workspace and project using Mule Project Settings in Visual Studio, if you select Add Global Element as shown below, visual studio will add DotNet connector configuration into your Mule project and also the dependent dot net dlls are auto copied into the resource folder
Once you build the project, you can notice this in the output window:
Refreshing your mule project in Anypoint studio, you will see the created and copied files:
Glitches: There are couple of glictches while working with the dot net connector itself. One of the most common and annoying one is, you get an error indicating Problem while fetching the metadata like below:
This could be because of different reasons like:
- The connector was not able to translate the dot net to read metadata which could be because of unsupported .net framework used
- It could also simply mean that you updated dot net code and referencing to new assembly but the studio has cached old assembly code
If it is the later, one trick which always worked for me click on Select Operation, then reference new assembly in the connector, then again select Execute Operation and then hit refresh next to the Type. Doing these steps seem to remove what ever was cached and load new assembly fine.
If you are using dot net connector configuration as a project resource, you may also face some refresh metadata issues like below if you update the dll.
In this situation, I found that recreating(deleting and re-adding) just the connector while leaving the connector configuration as is has helped getting past this error.
References: