question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interface method does not have an implementation exception

See original GitHub issue

When I upgraded a project today from 3.X to latests version 4.1.1 i got a odd error.

I have an interface like below and got the following error when calling A.Fake<Test>();

public interface Test
{
	void Test1<T>(IEnumerable<T> enumerable);
	void Test1<T>(IList<T> enumerable);
}

*ERROR

FakeCreationException: 
  Failed to create fake of type UserQuery+Test.

  Below is a list of reasons for failure per attempted constructor:
    No constructor arguments failed:
      No usable default constructor was found on the type UserQuery+Test.
      An exception of type System.TypeLoadException was caught during this call. Its message was:
      Method 'Test1' in type 'Castle.Proxies.ObjectProxy_9' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
         at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
         at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
         at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
         at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType() in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1_0.<GenerateCode>b__0(String n, INamingScope s) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) in C:\projects\fakeiteasy\src\FakeItEasy\AsyncReturnValueConfigurationExtensions.cs:line 0
         at FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.GenerateClassProxy(Type typeOfProxy, ProxyGenerationOptions options, IEnumerable`1 argumentsForConstructor, IInterceptor interceptor, IEnumerable`1 allInterfacesToImplement) in C:\projects\fakeiteasy\src\FakeItEasy\Creation\CastleDynamicProxy\CastleDynamicProxyGenerator.cs:line 174
         at FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.DoGenerateProxy(Type typeOfProxy, ProxyGenerationOptions options, IEnumerable`1 additionalInterfacesToImplement, IEnumerable`1 argumentsForConstructor, IInterceptor interceptor) in C:\projects\fakeiteasy\src\FakeItEasy\Creation\CastleDynamicProxy\CastleDynamicProxyGenerator.cs:line 159
         at FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.CreateProxyGeneratorResult(Type typeOfProxy, ProxyGenerationOptions options, IEnumerable`1 additionalInterfacesToImplement, IEnumerable`1 argumentsForConstructor, IFakeCallProcessorProvider fakeCallProcessorProvider) in C:\projects\fakeiteasy\src\FakeItEasy\Creation\CastleDynamicProxy\CastleDynamicProxyGenerator.cs:line 105

This works fine prior to 4.1.0 (both 3.X and 4.0.0).

I suspect it’s the upgrade of Castle.Core 4.1 to 4.2, but I’m unsure, because if I add a reference to Castle.Core 4.2.1 in my project it still work with FakeItEasy 4.0.0 and earlier.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
blairconradcommented, Nov 7, 2017

Oh, it’s nearly always faster for us to do it, but we very much enjoy community contributions (and assume that the community members enjoy making them - if I’m wrong here, please correct me).

If nothing else, I’m in mid-East Canada time, so you can always report back tonight with your progress and/or feelings, and I’ll be awake. 😉

I will warn you, though, that I’d enjoy a new spec for the use case. I would add a new Scenario to CreationSpecsBase. If you’ve not used xBehave.net before, fret not, since it’s a joy to use and the examples in that file are good to copy. In particular, CollectionOfFakeWithOptionBuilder is a good starting point (except that you’d only make one fake, of course).

The only tricky part about the test would be that since CreationSpecsBase is an abstract base class designed to test both generic and non-generic test creation methods. I’d create your fake using this.CreateFake<>() instead of the standard A.Fake<>().

Again, thanks for raising the issue and for agreeing to help us fix it!

1reaction
skarumcommented, Nov 7, 2017

I can do that 😃 I’ll look at it tonight (Europe time) and make a PR. If it’'s faster for you to make it yourself, then just go ahead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - TypeLoadException says 'no implementation', but it is ...
The error message complained that Method 'MyMethod' in type 'MyType' from assembly 'ImplementationAssembly' does not have an implementation ...
Read more >
c# - TypeLoadException says 'no implementation', but it is ...
I've got a very weird bug on our test machine. The error is: System.TypeLoadException: Method 'SetShort' in type 'DummyItem' from assembly ' ...
Read more >
How to handle a new method in the interface that is not ...
Another possibility is that you add two methods to the original interface and don't create a new one: Bool implementsAction4() and String ...
Read more >
c# - How to enforce implementation of interface to behave ...
There is no way to require an implementation to throw an exception through an interface, even in languages like Java where you can...
Read more >
Default interface methods - C# 8.0 draft feature specifications
An implementation declaration is permitted to explicitly implement a particular base interface method by qualifying the declaration with the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found