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 8537667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:57:19+00:00 2026-06-11T10:57:19+00:00

I’m just trying to get familiar with the new Fakes Isolation Framework in Visual

  • 0

I’m just trying to get familiar with the new Fakes Isolation Framework in Visual Studio 2012 RC but I’m consequently facing issues with ShimNotSupportedExceptions.

At the first tries, each single shim method I tried to hook up a delegate to, had thrown a ShimNotSupportedException when trying to run/debug the test.

[TestMethod]
public void GetFoo_ValidBar_ReturnsBaz()
{
    using(ShimsContext.Create())
    {
        ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59);

        const string expected = "20120811_102059";
        string actual = GetFoo();

        Assert.AreEqual(expected,actual);
    }
} 

This is the corresponding stack trace:

The
GetFoo_ValidBar_ReturnsBaz
test method has thrown an exception:
Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException:
System.DateTime
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InvokeEvent(T value, Action1 eh)
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.OnAttachedUnsupportedMethod(MethodBase method)
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.CheckInstrumentation(MethodBase
method)
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InternalAttachDetour(Object
optionalReceiver, MethodBase method, Delegate detourDelegate)
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.AttachDetour(Object
optionalReceiver, MethodBase method, Delegate detourDelegate)
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimMethod(Delegate
optionalStub, Object optionalReceiver, MethodBase method)
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShim(Delegate
optionalStub, Type receiverType, Object optionalReceiver, String name,
ShimBinding flags, Type returnType, Type[] parameterTypes)
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimPublicStatic(Delegate
optionalStub, Type receiverType, String name, Type returnType, Type[]
parameterTypes)
at System.Fakes.ShimDateTime.set_NowGet(Func’1 value)
at GetFoo_ValidBar_ReturnsBaz()
in BazTests.cs: line 48.

After having read the two threads I had found at MSDN dealing with this issue I followed their instructions (turning CodeCoverage off, deleting .testsettings file) which didn’t work for me!

Nevertheless I have found a workaround for this issue:

By firstly running all tests from the Test Explorer (instead of using the “MSTest Test (click to run)” button directly out of the coding area) everything worked correctly and no exceptions were thrown. Afterwards I could even debug the test and the assignment to the shim method worked just as expected.

This worked for all following shims I used as well.

But now I’m having the same issue again when trying to implement fakes of the MS Enterprise Library for database access.

This is what the test looks like:

[TestMethod]
public void GetFooFromEF_NonEmptyDataReader_ObjectsCorrectlyInstantiated()
{
    using(ShimsContext.Create()){
        var dataReader = new StubIDataReader()
            {
                ItemGetString = s => 1,
                DepthGet = () => 2
            };

        ShimFoo.GetBar = guid => dataReader;

        var bar = new StubIBar()
        {
            ConvertIBarToBaz = record => null
        };

        ShimQux.AllInstances.GetBar = (a, b) => bar;

        var dbFactory = new StubDbProviderFactory();
        var db = new StubDatabase("test", dbFactory);
        ShimDatabaseFactory.CreateDatabaseString = s => db;

        List<BarInformation> actual = accessor.InvokeStatic("GetBar",
                                                                new Object[] { }) as List<BarInformation>;
        Assert.IsTrue(true);
    }
}

The first two shim assignments (ShimFoo & ShimQux) are working as expected. But ShimDatabaseFactory.CreateDatabaseString (which is supposed to make DatabaseFactory.CreateDatabase(string) return a stub database when trying to create a new database instance) throws a ShimNotSupportedException again. And I just can’t figure out why!

Do you have any ideas what went wrong here?

I would appreciate any input on this.

Thanks,

Benjamin

  • 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-11T10:57:20+00:00Added an answer on June 11, 2026 at 10:57 am

    I had the same exact problem. Try to remove all testsettings files (both from disk and solution), and make sure your solution does not reference any testsettings files.

    Also make sure you’re using the visual studio testrunner (and not resharper etc. which is instrumenting the code).

    I’ve written two blogposts about these issues which may be helpful:

    Visual Studio 2012 Fakes – ShimNotSupportedException when debugging tests

    Unit testing – Visual Studio 2012 Fakes in Team City

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.