ShimNotSupportedException in MS VisualStudio 2012
===

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 `ShimNotSupportedException`s.
<br>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.

<!-- language: c# -->

    [TestMethod]
    public void GetTimeStamp_ValidDate_ReturnsTimestamp()
    {
        using(ShimsContext.Create())
        {
            ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59);
     
            const string expected = "20120811_102059";
            string actual = Miscellaneous.GetTimeStamp();
    
            Assert.AreEqual(expected,actual);
        }
    } 

This is the corresponding stack trace:

> The
> AMS_CommonFunctionality.Tests.MiscellaneousTests.GetTimeStamp_ValidDate_ReturnsTimestamp
> 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 AMS_CommonFunctionality.Tests.MiscellaneousTests.GetTimeStamp_ValidDate_ReturnsTimestamp()
> in MiscellaneousTests.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!
<br>Nevertheless I have found a workaround for this issue:
<br>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.
<br>This worked for all following shims I used as well. 
<br>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:

<!-- language: c# -->

    [TestMethod]
    public void GetPerformanceData_NonEmptyDataReader_ObjectsCorrectlyInstantiated()
    {
        using(ShimsContext.Create()){
            var dataReader = new StubIDataReader()
                {
                    ItemGetString = s => 1,
                    DepthGet = () => 2
                };
    
            ShimStoredProcedureAccess.GetPerformanceDataGuid = guid => dataReader;
    
            var marketingChannel = new StubIMarketingChannel()
            {
                ConvertIDataRecordToAdvertInformationIDataRecord = record => null
            };
    
            ShimMarketingChannelFactory.AllInstances.GetChannelAdvertiser = (factory, advertiser) => marketingChannel;
    
            var dbFactory = new StubDbProviderFactory();
            var db = new StubDatabase("test", dbFactory);
            ShimDatabaseFactory.CreateDatabaseString = s => db;
    
            List<AdvertInformation> actual = accessor.InvokeStatic("GetPerformanceData",
                                                                    new Object[] { }) as List<AdvertInformation>;
            Assert.IsTrue(true);
        }
    }

The first two shim assignments (ShimStoredProcedureAccess & ShimMarketingChannelFactory) 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!
<br>Do you have any ideas what went wrong here?

I would appreciate any input on this.

Thanks,
<br>Benjamin
