When your code is executing in the Visual Studio integrated development environment (IDE), you can avoid the exception dialog box that appears for specific MDA events. To do that, on the Debug menu, click Exceptions. (If the Debug menu does not contain an Exceptions command, click Customize on the Tools menu to add it.) In the Exceptions dialog box, expand the Managed Debugging Assistants list, and then clear the Thrown check box for the individual MDA. For example, to avoid the exception dialog box for a contextSwitchDeadlock MDA clear the Thrown check box next to its name in the Managed Debugging Assistants list. You can also use this dialog box to enable MDAs.

So if you are getting something like this – PinvokeStackImbalance when you are using some invoke – such as
MethodInfo mi = rs.GetType().GetMethod(“YourUmanagedFunction”,
new Type[] { typeof(int), typeof(string), typeof(StringBuilder) });
mi = mi.MakeGenericMethod(typeof(TEntity));

//TODO: Implement List
results = (TEntity)mi.Invoke(rs, new object[] { 110, this.Path, query });

You should unmark it in the Debug-> Exceptions -> Managed Debugging Assistants :

That should solve the problem!