Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6205105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:12:48+00:00 2026-05-24T05:12:48+00:00

I have the following setup code: MockOf<IObjectSet<Dummy>>().Setup(c => c.AddObject(dummy)).Verifiable(); MockOf<IObjectContextWrapper>().Setup(c => c.GetObjectSet<Dummy>()).Returns(MockOf<IObjectSet<Dummy>>().Object); where Dummy

  • 0

I have the following setup code:

MockOf<IObjectSet<Dummy>>().Setup(c => c.AddObject(dummy)).Verifiable();
MockOf<IObjectContextWrapper>().Setup(c => c.GetObjectSet<Dummy>()).Returns(MockOf<IObjectSet<Dummy>>().Object);

where Dummy is an empty class definition, and dummy is a Dummy. MockOf<T>() is a mock managing feature on a base class, which basically makes sure that each time it’s called on a type, it returns the same mock instance.

The test containing this setup code fails with a TypeLoadException and the following message:

System.TypeLoadException : Type ‘IObjectSet`1Proxy389e220f10aa4d9281d0b9e136edc1d4’ from assembly ‘DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69’ is attempting to implement an inaccessible interface.

at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
at Moq.Mock1.<InitializeInstance>b__0()
at Moq.Mock
1.InitializeInstance()
at Moq.Mock`1.get_Object()
at OddEnds.Tests.Data.EntityFramework.RepositoryTest.Delete_DeletesObjectFromObjectSet() in RepositoryTest.cs: line 43

I have imported System.Data.Objects and referenced both System.Data.Entity.dll and Microsoft.Data.Entity.CTP.dll in both the test project and the project where the class being tested resides. The build succeeds with no errors, warnings or messages (except a few related to Code Contracts…)

How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:12:49+00:00Added an answer on May 24, 2026 at 5:12 am

    Are any of the interfaces or class you are using in your tests internal? Are you using something like [assembly: InternalsVisibleTo("YourTestAssembly")] in order to get things to compile?

    If so, you’ll also need to add one for DynamicProxyGenAssembly2 in order for Moq to dynamically generate the proxy for the classes.

    //goes in the AssemblyInfo.cs where the internal interfaces / classes are defined
    [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]  
    

    Here is a relevent post about the topic

    http://sonofpirate.blogspot.com/2009/09/my-first-foray-into-unit-testing-with.html

    I hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup for Moq: ... other code to setup bigMoq object
I have the following domain model setup using EF code first: public class User
I have the following setup: Code on my local machine (OS X) shared as
I have the following piece of code: // setup the AJAX request var pageRequest
I have the following setup, and the empty view text doesn't show up... protected
I have the following code: [SetUp] public void SetMeUp() { Mapper.CreateMap<SourceObject, DestinationObject>(); } [Test]
My Project Setup I have the following project setup: \program.jar \images\logo.png In my code,
I have the following ul setup: <div id=sidebar> <ul id=themenu class=sf-menu sf-vertical> <li> <a
I have the following setup: A templated class SpecialModel: template<typename A, typename B> class
Ok so i have the following code setup which seems to work fine: user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.