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

  • Home
  • SEARCH
  • 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 8371265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:07:21+00:00 2026-06-09T14:07:21+00:00

I set up a simple test project in Visual Studio 2010. For unit tests

  • 0

I set up a simple test project in Visual Studio 2010. For unit tests I use nunit 2.6.1 and for mocking FakeItEasy 1.7.4582.63 which I install via NuGet.

I try to fake a DbDataAdapter using the following code:

using System.Data.Common;
using FakeItEasy;
using NUnit.Framework;

namespace huhu
{
    [TestFixture]
    public class Class1
    {
        [Test]
        public void test1()
        {
            A.Fake<DbDataAdapter>();
        }
    }
}

When I run the test using .NET framework 3.5 everything works fine and test1 will pass. But, when I set the framework version to .NET 4.0, I get the following exception:

FakeItEasy.Core.FakeCreationException : 
  Failed to create fake of type "System.Data.Common.DbDataAdapter".

  Below is a list of reasons for failure per attempted constructor:
    No constructor arguments failed:
      No default constructor was found on the type System.Data.Common.DbDataAdapter.
    The following constructors were not tried:
      (*System.Data.Common.DbDataAdapter)

      Types marked with * could not be resolved, register them in the current
      IFakeObjectContainer to enable these constructors.

Any ideas how to make things work in .NET 4.0 are appreciated!

Bye, Jörg

  • 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-06-09T14:07:22+00:00Added an answer on June 9, 2026 at 2:07 pm

    Usually such problems come not from FakeItEasy itself, but from Castle.DynamicProxy, library which FakeItEasy uses to create fake types. Investigating this little further leads to following exception thrown by Castle:

    Due to limitations in CLR, DynamicProxy was unable to successfully replicate non-inheritable attribute System.Security.Permissions.PermissionSetAttribute on System.Data.Common.DbDataAdapter.CloneInternals. To avoid this error you can chose not to replicate this attribute type by calling ‘Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(System.Security.Permissions.PermissionSetAttribute))’.

    Inspecting DbDataAdapter base class’ source code (DataAdapter) shows that this indeed is the case:

    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    protected virtual DataAdapter CloneInternals()
    

    Castle already hinted how to solve this problem. Before creating your fake, simply instruct Castle not to replicate PermissionSetAttribute:

    Castle.DynamicProxy.Generators
       .AttributesToAvoidReplicating.Add(typeof(PermissionSetAttribute));
    var fake = A.Fake<DbDataAdapter>();
    

    Two things to note:

    1. You need to reference Castle.Core.dll in your project (available here)
    2. Keep in mind FakeItEasy will only be able to mock virtual methods of this DbDataAdapter (again, this is Castle.DynamicProxy/CLR limitation – I briefly explained why this is the case in my blog post)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just set up a simple project to test the functionality of the maven exec
I want to make a simple test programm which set the color of the
I'm using VSTS 2K8 and I've set up a Unit Test Project. In it,
I'm using NUnit for my unit tests and I have my unit test class
Hi, I have done the following : Start Visual Studio 2010 New Project >
In attempting to create an initial, failing unit test in Visual Studio Professonal 2008's
I created a configuration named Test via Visual Studio which currently just takes all
I have a unit test project set up in the same solution as my
I've set up a very simple prototype to test out the YUI Uploader. (flash
I have a fairly simple set of functionality for which I have multiple implementations,

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.