Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework4.3 and Unit Testing. Access Violation Exception. Attempted to read or write protected memory
    primarykey
    data
    text
    <p>I am using EF4.3, ASP.NET MVC4, Microsoft.VisualStudio.TestTools.UnitTesting. </p> <p>Code works fine. I added Unit tests to test Controllers. The Unit tests fails with following exception : </p> <blockquote> <p>Access Violation Exception. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</p> <p>at ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(MyBusinessEntity).Assembly);</p> </blockquote> <p>I have added [assembly: InternalsVisibleTo("TestProject")] to my Web project AssemblyInfo.cs</p> <p>Any suggestions ?</p> <p>Unit test code:</p> <pre><code> [TestMethod] public void GetEntity() { // Arrange MyControllercontroller = new MyController(); // Act var result = controller.GetEntity("737464305") as JsonResult; dynamic data = result.Data; // Assert Assert.IsNotNull(data); Assert.AreEqual("0", data.ProcessStatus); } </code></pre> <p>Controller action invokes a Stored Procedure using Entity Framework4.3 DBContext. The result of SP call is mapped to a Complex Type. The DBContext code for the SP call is :</p> <pre><code>public virtual ObjectResult&lt;MyEntity&gt; MYSP(string inparam) { ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(MyEntity).Assembly); var inparamParameter = inparam != null ? new ObjectParameter("inparam", inparam) : new ObjectParameter("inparam", typeof(string)); return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;MyEntity&gt;("MYSP", inparamParameter ); } </code></pre> <p><strong>In general code works fine. However, Access Violation Error is thrown when Controller action is tested using Unit Test. in line ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(MyEntity).Assembly);</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload