AccessViolationException error with Cthru

Oct 10, 2010 at 3:31 AM

Hi

I was doing a pretty simple Cthru aspect test and the test is to "log" every call to the SqlCommand class in System.Data

...........

            CThruEngine.AddAspect(new RxAspect());
            CThruEngine.StartListening();

            var Context = new MyDB();

            var Subs = (from S in Context.Subscribers              //Linq2Sql query
                        select S).Take(3).ToList();

 

...........

    public class RxAspect : Aspect
    {
        public override bool ShouldIntercept(InterceptInfo info)
        {
            if (info.TypeName.Contains("System.Data.Common.DbCommand.SqlCommand"))
            {
                return true;
            }
            return false;
        }
        public override void StaticConstructorBehavior(DuringCallbackEventArgs e)
        {
            e.MethodBehavior = MethodBehaviors.CallRealMethod;
        }


        public override void MethodBehavior(DuringCallbackEventArgs e)
        {
      //       Console.WriteLine(e.MethodName);
            base.MethodBehavior(e);
        }
    }

 

 

The exception I get in the Linq statement is

 

System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
  Source="System.Core"
  StackTrace:
       at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)
       at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 49
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

Any ideas?

Coordinator
Oct 10, 2010 at 6:12 PM
are you using postsharp by any chance?

On Sun, Oct 10, 2010 at 5:31 AM, sune42 <notifications@codeplex.com> wrote:

From: sune42

Hi

I was doing a pretty simple Cthru aspect test and the test is to "log" every call to the SqlCommand class in System.Data

...........

            CThruEngine.AddAspect(new RxAspect());
            CThruEngine.StartListening();

            var Context = new MyDB();

            var Subs = (from S in Context.Subscribers              //Linq2Sql query
                        select S).Take(3).ToList();

 

...........

    public class RxAspect : Aspect
    {
        public override bool ShouldIntercept(InterceptInfo info)
        {
            if (info.TypeName.Contains("System.Data.Common.DbCommand.SqlCommand"))
            {
                return true;
            }
            return false;
        }
        public override void StaticConstructorBehavior(DuringCallbackEventArgs e)
        {
            e.MethodBehavior = MethodBehaviors.CallRealMethod;
        }


        public override void MethodBehavior(DuringCallbackEventArgs e)
        {
      //       Console.WriteLine(e.MethodName);
            base.MethodBehavior(e);
        }
    }

 

 

The exception I get in the Linq statement is

 

System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
  Source="System.Core"
  StackTrace:
       at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)
       at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 49
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

Any ideas?

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)
Oct 11, 2010 at 6:49 AM

Yes, I have it installed. But it is not part of the solution/project that I am working on. So I uninstalled postsharp, restarted Visual studio, but still get the same problem

 

System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
  Source="System.Core"
  StackTrace:
       at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)
       at TypeMockTest.Program.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\TypeMockTest\TypeMockTest\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException

 

I only reference CThru, TypeMock, TypeMock.ArrangeActAssert

I even re-implemented my test solution as follow

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TypeMock;
using CThru;

namespace TypeMockTest
{
    class Program
    {
        static void Main(string[] args)
        {
            CThruEngine.StartListening();

            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.ProjectName);
            }

            Console.ReadKey();
        }
    }
}

Oct 11, 2010 at 6:59 AM

I even restarted my machine and the conclusion from the sourcecode above is that when I remove the line "  CThruEngine.StartListening();" it works, and adding it gives me the Access exception.

Also not that I haven't added any aspects yet.  I do get the same error if I add one.

 

If I stop using CThru and just start using typemock instead with this stupid example it still fails.

 

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using TypeMock;
using CThru;
using TypeMock.ArrangeActAssert;

namespace TypeMockTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var Rrd = Isolate.Fake.Instance<Test>();

            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.ProjectName);
            }

            Console.ReadKey();
        }
    }

    public class Test
    {
       

    }
}

The debug out put is

 

'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Users\Administrator\Documents\Visual Studio 2008\Projects\TypeMockTest\TypeMockTest\bin\Debug\TypeMockTest.exe', Symbols loaded.
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Accessibility\2.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Users\Administrator\Documents\Visual Studio 2008\Projects\TypeMockTest\TypeMockTest\bin\Debug\Typemock.ArrangeActAssert.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Typemock.Interceptors\6.0.4.0__3dae460033b8d8e2\Typemock.Interceptors.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Configuration\6.0.4.0__3dae460033b8d8e2\Configuration.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Runtime.Remoting\2.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
A first chance exception of type 'System.AccessViolationException' occurred in TypeMockTest.exe
The program '[7156] TypeMockTest.vshost.exe: Managed' has exited with code 0 (0x0).

 

Coordinator
Oct 11, 2010 at 7:54 AM
Can you please download the cthru examples from 

they should run just fine on your machine out of the box.
if they don't, we'll have a better a clue perhaps what is happening.

On Mon, Oct 11, 2010 at 8:59 AM, sune42 <notifications@codeplex.com> wrote:

From: sune42

I even restarted my machine and the conclusion from the sourcecode above is that when I remove the line "  CThruEngine.StartListening();" it works, and adding it gives me the Access exception.

Also not that I haven't added any aspects yet.  I do get the same error if I add one.

 

If I stop using CThru and just start using typemock instead with this stupid example it still fails.

 

using System;
using System.Collections.Generic;
using System.Data.SqlClient;

using System.Linq;
using System.Text;
using TypeMock;
using CThru;
using TypeMock.ArrangeActAssert;


namespace TypeMockTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var Rrd = Isolate.Fake.Instance<Test>();


            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.ProjectName);
            }

            Console.ReadKey();
        }
    }

    public class Test
    {
       

    }
}

The debug out put is

 

'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Users\Administrator\Documents\Visual Studio 2008\Projects\TypeMockTest\TypeMockTest\bin\Debug\TypeMockTest.exe', Symbols loaded.
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Accessibility\2.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Users\Administrator\Documents\Visual Studio 2008\Projects\TypeMockTest\TypeMockTest\bin\Debug\Typemock.ArrangeActAssert.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Typemock.Interceptors\6.0.4.0__3dae460033b8d8e2\Typemock.Interceptors.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Configuration\6.0.4.0__3dae460033b8d8e2\Configuration.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Runtime.Remoting\2.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'
'TypeMockTest.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
A first chance exception of type 'System.AccessViolationException' occurred in TypeMockTest.exe
The program '[7156] TypeMockTest.vshost.exe: Managed' has exited with code 0 (0x0).

 

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)
Oct 11, 2010 at 8:24 AM

Hi

When I run the 5 tests in ControlTests_vs2010.CS, they all pass.

 

 

Coordinator
Oct 11, 2010 at 8:30 AM
try ti add the linq statement

On Mon, Oct 11, 2010 at 10:24 AM, sune42 <notifications@codeplex.com> wrote:

From: sune42

Hi

When I run the 5 tests in ControlTests_vs2010.CS, they all pass.

 

 

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)
Oct 11, 2010 at 8:56 AM

when I add the linq2sql query part to one of the tests in the ControlTests_vs2010.CS projecti it works fine. The solution that I have trouble with is a VS2008 project though. Its a bit wierd!


        [Test,SilverlightUnitTest]
        public void SetProperty()
        {
            var Rrd = Isolate.Fake.Instance<Test>();
            CThruEngine.StartListening();

            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.Name);
            }

            var panel = new StackPanel();
            Assert.AreEqual(0,panel.Children.Count);

...

 

Coordinator
Oct 12, 2010 at 5:54 AM
interesting...
we'll have to investigate further.
can you send the solution that doesn't work?

On Mon, Oct 11, 2010 at 10:56 AM, sune42 <notifications@codeplex.com> wrote:

From: sune42

when I add the linq2sql query part to one of the tests in the ControlTests_vs2010.CS projecti it works fine. The solution that I have trouble with is a VS2008 project though. Its a bit wierd!


        [Test,SilverlightUnitTest]
        public void SetProperty()


        {
            var Rrd = Isolate.Fake.Instance<Test>();
            CThruEngine.StartListening();


            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.Name);
            }

            var panel = new StackPanel();
            Assert.AreEqual(0,panel.Children.Count);

...

 

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)
Coordinator
Oct 14, 2010 at 8:56 AM
I can't repro. I've added this to our support, so you'll be well taken care of.

On Tue, Oct 12, 2010 at 7:54 AM, Roy Osherove <roy@osherove.com> wrote:
interesting...
we'll have to investigate further.
can you send the solution that doesn't work?


On Mon, Oct 11, 2010 at 10:56 AM, sune42 <notifications@codeplex.com> wrote:

From: sune42

when I add the linq2sql query part to one of the tests in the ControlTests_vs2010.CS projecti it works fine. The solution that I have trouble with is a VS2008 project though. Its a bit wierd!


        [Test,SilverlightUnitTest]
        public void SetProperty()


        {
            var Rrd = Isolate.Fake.Instance<Test>();
            CThruEngine.StartListening();


            var context = new mydbDataContext();

            var projs = from P in context.Projects
                        select P;

            foreach (var prj in projs)
            {
                Console.WriteLine(prj.Name);
            }

            var panel = new StackPanel();
            Assert.AreEqual(0,panel.Children.Count);

...

 

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)



--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)