c# - ResolutionFailedException when register a Unity interceptor -


i have code.

class program {     static void main(string[] args)     {         iunitycontainer container = new unitycontainer();         container.addnewextension<interception>();         container.registertype<itestinterception, testinterception>(new transientlifetimemanager(),                                                  new interceptor<interfaceinterceptor>(),                                                  new interceptionbehavior<policyinjectionbehavior>());           container.configure<interception>()                  .addpolicy("mypolicy")                  .addmatchingrule(new membernamematchingrule("test"))                  .addcallhandler<faulthandler>();          try         {             var tester = container.resolve<itestinterception>();             tester.test();         }         catch (exception e)         {             console.writeline(e.gettype() + "\n\n");         }         console.readkey();     } }  class alwaysmatchingrule : imatchingrule {     public bool matches(methodbase member)     {         return true;     } }  interface itestinterception {     void test(); }  class testinterception : itestinterception {     public void test()     {         throw new argumentnullexception("null");     } }  class faulthandler : icallhandler {     public imethodreturn invoke(imethodinvocation input, getnexthandlerdelegate getnext)     {         console.writeline("invoke called");         imethodreturn result = getnext()(input, getnext);         exception e = result.exception;         if (e == null)             return result;          return input.createexceptionmethodreturn(new invalidoperationexception("in interceptor", e));     }      public int order { get; set; } } 

when runs, has resolutionfailedexception.

resolution of dependency failed, type = "testunity.itestinterception", name = "(none)". exception occurred while: while resolving. exception is: typeloadexception - type 'dynamicmodule.ns.wrapped_itestinterception_0e954c5db37c4c4ebf99acaee12e93f7' assembly 'unity_ilemit_interfaceproxies, version=0.0.0.0,

can explain me how solve problem?

the innerexception message says all:

type 'dynamicmodule.ns.wrapped_itestinterception_c8a0c8bf8a3d48a5b7f85924fab5711f' assembly 'unity_ilemit_interfaceproxies, version=0.0.0.0, culture=neutral, publickeytoken=null' is attempting implement inaccessible interface.

you need make interface public:

public interface itestinterception {     void test(); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -