New Posts New Posts RSS Feed: Extension Method MakeWeak error
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Extension Method MakeWeak error

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: Extension Method MakeWeak error
    Posted: 09-Nov-2012 at 5:25am
I trying to implement a global cache repository as TempHire does. So, when registering an event with weak reference I receive an error:

Error Message: 
Exception has been thrown by the target of an invocation.

Detail:
Attempt by method 'IdeaBlade.Core.WeakEventHandler`2<System.__Canon,System.__Canon>..ctor(System.EventHandler`1<System.__Canon>, IdeaBlade.Core.UnregisterCallback`1<System.__Canon>)' to access method 'DomainServices.Helpers.GlobalCacheRepository`1<System.__Canon>.OnManagerCreated(System.Object, IdeaBlade.EntityModel.EntityManagerCreatedEventArgs)' failed.

Code:
 public GlobalCacheRepository(IEntityManagerProvider entityManagerProvider, IGlobalCache globalCache)
            : base(entityManagerProvider)
        {
            _globalCache = globalCache;
            
            entityManagerProvider.ManagerCreated += new EventHandler<EntityManagerCreatedEventArgs>(OnManagerCreated)
               .MakeWeak(eh => entityManagerProvider.ManagerCreated -= eh);

            if (globalCache != null)
                DefaultQueryStrategy = QueryStrategy.CacheOnly;
        }

What am I doing wrong?

PS: If I don't use MakeWeak it works.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 09-Nov-2012 at 5:57am
You need to open up your AssemblyInfo.cs file in your DomainServices project and add this line:

[assembly: InternalsVisibleTo("IdeaBlade.Core.SL, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b3f302890eb528"
                                                     + "1a7ab39b936ad9e0eded7c4a41abb440bead71ff5a31d51e865606b2a7e6d0b9dd0d92b113b9d1"
                                                     + "0fb13f01fb5d856e99c1e61777cf4772d29bad7e66ffb93fc5cbd63b395046c06ff57db6ecbeee"
                                                     + "4bdd6effc405878d65cfc4911708ed650da935d733fc5dc707f74910e025ac080543e01a6cc863"
                                                     + "b9f85ffc")]

Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 09-Nov-2012 at 7:47am
It works fine.

Thanks Mark.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down