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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi All,

I am getting the below mentioned error, when executing the code block.

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

Please share any solutions, to get it resolved.

Thanks in advance !!!
asked by srinathej (680 points)

4 Answers

0 votes
Hi,

Can you please post the test code? Which line throws this exception exactly?
answered by igal (5.7k points)
0 votes
quickLinksDA = new QuickLinksDA();

//setup a fake data context
var fakeDataContext = Isolate.Fake.Instance<EdxquicklinksDataContext>();
Isolate.Swap.NextInstance<EdxquicklinksDataContext>().With(fakeDataContext);

Isolate.WhenCalled(() => fakeDataContext.EDXQuickLinks)
.WillReturnCollectionValuesOf(fakeItems.AsQueryable());

Mock spSecurityMock = MockManager.Mock(typeof(SPSecurity));
spSecurityMock.MockMethodCalled += new MockMethodCalledEventHandler(
GSK.eDX.NUnit.TestUtil.spSecuritycMock_MockMethodCalled);

spSecurityMock.ExpectAlways("RunWithElevatedPrivileges");

SPSite fakeSite = Isolate.Fake.Instance<SPSite>(Members.ReturnRecursiveFakes);
Isolate.Swap.NextInstance<SPSite>().With(fakeSite);

SPWeb fakeWeb = Isolate.Fake.Instance<SPWeb>();
Isolate.WhenCalled(() => fakeSite.OpenWeb()).WillReturn(fakeWeb);
Isolate.WhenCalled(() => fakeWeb.Url).WillReturn(webUrl);

//Act
List<QuickLinksView> quickLinks = quickLinksDA.GetQuickLinks(
fileName, webUrl, role);

//Assert



Which in turn calling the below mentioned code: public static void spSecuritycMock_MockMethodCalled(object sender, MockMethodCallEventArgs e)
{
if (e.CalledMethodName.Equals("RunWithElevatedPrivileges"))
{
SPSecurity.CodeToRunElevated del = (SPSecurity.CodeToRunElevated)e.SentArguments[0];
IAsyncResult res = del.BeginInvoke(null, null);
res.AsyncWaitHandle.WaitOne();
del.EndInvoke(res);
}
}

Assert.AreEqual(4, quickLinks.Count);


I am getting the error from Bold and Underlined part
answered by srinathej (680 points)
0 votes
This might be related to an issue we currently have with IQueryable in 64-bit, which causes AccessViolationException...

Could you try running your test in x86, and see if the problem persists?

Thanks!
answered by igal (5.7k points)
0 votes
Hi,

Thanks for reply.

Can we have any Patches supported by Typemock, to make it compatible for x64 machines, because as our servers are running on the same.
answered by srinathej (680 points)
...