This worked without issue in 5.2 or 5.3??? I can't remember what this was written against when it worked as we haven't worked with this libary in some time. I had to make a change today and we are currently on 5.4.4 so I had to update my references and now fails. This is inside of a test helper method that I call from many tests.
DbConnection fakeConnection = Isolate.Fake.Instance<DbConnection>(l);
DbCommand fakeCmd = Isolate.Fake.Instance<DbCommand>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => Utilities.CreateConnection()).WillReturn(fakeConnection);
Isolate.WhenCalled(() => fakeConnection.CreateCommand()).WillReturn(fakeCmd);
The error you will receive on the first and second line:
System.TypeLoadException: Declaration referenced in a method implementation cannot be a final method. Type: 'Mock0008DbCommand'. Assembly: 'DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0857b23fb3f20d9'.
I worked around this by creating two stub classes:
FakeDbConnection (inherits from DbConnection) and FakeDbCommand (inherits from DbCommand) and then just changed my code to the following:
DbConnection fakeConnection = Isolate.Fake.Instance<FakeDbConnection>();
DbCommand fakeCmd = Isolate.Fake.Instance<FakeDbCommand>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => Utilities.CreateConnection()).WillReturn(fakeConnection);
Isolate.WhenCalled(() => fakeConnection.CreateCommand()).WillReturn(fakeCmd);