DotMemoryUnitException : dotMemory Unit methods were called from outside a test method


I am using dotMemory Unit with NUnit Framework. And get this below exception when i try to run my Test case in Visual Studio with "Run under dotMemory Unit".


DotMemoryUnitException : dotMemory Unit methods were called from outside a test method:
- If you work with a unit test runner that is not supported out of the box, then probably calls to dotMemory Unit were made from outside the DotMemoryUnitController TestStart() and TestEnd() methods or these methods were called in the wrong order. Learn more about the DotMemoryUnitController class:
- If your unit test runner is supported out of the box, then probably your assembly does not use dotMemory Unit by itself but calls the code from other assemblies that do use dotMemory Unit. To fix the issue, apply the 'EnableDotMemoryUnitSupportAttribute' attribute to your assembly.
at JetBrains.dotMemoryUnit.Client.DotMemoryUnitProxy.AssertIsInsideTest()
at JetBrains.dotMemoryUnit.Client.DotMemoryUnitProxy.get_IsEnabled()
at JetBrains.dotMemoryUnit.dotMemory.Check(Action`1 check)


My test case is something like this 

public async Task SomeTestCase()


//At end of test case

memory => Assert.That(memory.GetObjects(where => where.Type.Is<MyType>()), Is.EqualTo(0)));



As far as i understand Nunit is supported by dotMemory Unit. 

I have also added [assembly: EnableDotMemoryUnitSupport] in my test case lib


1 comment
Comment actions Permalink

dotMemoryUnit doesn’t support async tests and parallel test execution. Even if it was possible, memory state from one test or async call would affect memory from another test or async call. For the same reason, we don’t recommend to call dotMemory.Check from non-test threads.

Most likely, dotMemory.Check wasn't called from the test method but from its continuation in another thread. We recommend avoiding parallel tasks execution when dotMemory.Check is in progress and rewriting this method in a more synchronous style.

Sorry for the inconvenience.


Please sign in to leave a comment.