I have a problem with layout settings, so I can call Marshal.ReleaseComObject()Mocked on my object.
I use Moq to customize the layout of the IFeature type (from a third-party interface library). The breadboard installation is quite simple:
var featureMock = new Mock<IFeature>();
IFeature feature = featureMock.Object;
In my code, an object object is created in a while loop, passing through the cursor ( FeatureCursor) type. Due to outdated third-party library problems, the object Featuredetected memory leak problems. Thus, I have to free objects through Marshal.ReleaseComObject(), as shown in the code;
public class XXX
{
public void DoThis()
{
IFeatureCursor featureCursor;
IFeature feature = null;
while ((feature = featureCursor.NextFeature)!= null)
{
Marshal.ReleaseComObject(feature);
}
}
}
It works when I use a real sign and functions, but when I mock a function in unittest, I get an error message:
"System.ArgumentException : The object type must be __ComObject or derived from __ComObject."
But how to apply this to my mock object?