chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I'm not sure if this bug should be address to your team, but I'll take a risk and try to ask it since I use typemock.net in all my tests.

I've got AccessViolationException in one of my tests when I run all tests in assembly. BUT IT'S SUCCEDED in either of the following:
1) I run this test along
2) I rename test class name (test fixture class name, not the tested class) so it changes the position is test order
3) I add new dummy test class (one emtpy test method) with the name like the failed one + suffux , but so the dummy one is placed before the test fixture.
4) I remove any of other test fixture before this one.

In any of this options the test succeeded.

Error occurs in the following real applicatrion class method, line retInstance.Initialize()

        public static Service Get<Service>() where Service : IService, new()
        {
            Service retInstance = (Service) instances[typeof(Service)];

            if (retInstance == null)
            {
                lock (syncRoot)
                {
                    retInstance = (Service) instances[typeof(Service)];
                    
                    if (retInstance == null)
                    {
                        retInstance = new Service();
                        retInstance.Initialize();
                        instances[typeof(Service)] = retInstance;
                    }
                }
            }

            return retInstance;
        }


Have no idea, why. Do you? What would you suggest to check?
asked by ezaritov (2.8k points)

9 Answers

0 votes
Hi,
This seems like the tests are dependant.
This could happen when object states are not reset between tests.

You could use ObjectState once you find out what the problem is.
Or you might have mocked out some constructor or static constructor that will leave the object in the bad state.

Please send a complete error stack to further investigate.
answered by scott (32k points)
0 votes
We are also getting this error occasionally. It is really weird, because it does not happen all the time. When I disable TypeMock, the error does not occur. Seems to me as though this is a memory leak.
answered by trumpi (140 points)
0 votes
I can report the same problem, an occasional accessviolation. We're running all our tests at night and this is breaking every time.

We have the same result: we can fix it by running the test alone. Sometimes, it requires running MSTest /noisolation, but I can't do that through the GUI.
answered by jeffozvold (1.4k points)
0 votes
I was running 3.1.3. I will upgrade and see if the problem is resolved. I will repost if not.
answered by jeffozvold (1.4k points)
0 votes
I use the newest version 3.1.4.0 and get this AccessViolationException again and again in Visual Studio 2005. Using UnitTest in a Test project.

I tried everything from:
- adding MockManager.ClearAll() in every unittest class in [ClassInitialize]
- adding MockManager.ClearAll() in every unittest class in [ClassCleanup]
- adding MockManager.ClearAll() in every unittest class in [TestInitialize]
- adding MockManager.ClearAll() in every unittest class in [TestCleanup]
- Adding everywhere MockManager.Verify()

All to try to cleanup TypeMock so the 'memory is not corrupt'...

But now and then (more now then then :-( ) a get the exception. Sometimes 7 times in a row, and then (without any changes) the test will run as expected...

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Does anyone know a workaround? Or some other way to nicely clean up tipemock?
answered by denman (180 points)
0 votes
Hi denman
In version 3.5 we solved few problems regarding access violation.
I will send you the link to download a preview offline.
answered by ohad (35.4k points)
0 votes
Hi Ohad,

I'm experiencing the same problem running verion 3.1.4 with NUnit from NAnt. Could you send me a link to a version that has resolved this problem?

Thanks in advance, Joe
answered by Joe (140 points)
0 votes
Hi Joe.
I sent you the link.
I hope it will help. :D
answered by ohad (35.4k points)
0 votes
Hi denman
In version 3.5 we solved few problems regarding access violation.
I will send you the link to download a preview offline.


Hi Ohad,

Thanx for the quick response.
I will be testing now with the TypeMock.net version 3.5
And will let you know if this version solves our problems.

Because the problem shows itself now and then, I cannot give you an answer soon.

I'm working for KPN, the biggest telecom company of The Netherlands.
answered by denman (180 points)
...