{"action":"opened","issue":{"url":"https://api.github.com/repos/jduv/AppDomainToolkit/issues/18","labels_url":"https://api.github.com/repos/jduv/AppDomainToolkit/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/jduv/AppDomainToolkit/issues/18/comments","events_url":"https://api.github.com/repos/jduv/AppDomainToolkit/issues/18/events","html_url":"https://github.com/jduv/AppDomainToolkit/issues/18","id":69644754,"number":18,"title":"IDisposable usage is not intuitive","user":{"login":"fnajera-rac-de","id":7532590,"avatar_url":"https://avatars.githubusercontent.com/u/7532590?v=3","gravatar_id":"","url":"https://api.github.com/users/fnajera-rac-de","html_url":"https://github.com/fnajera-rac-de","followers_url":"https://api.github.com/users/fnajera-rac-de/followers","following_url":"https://api.github.com/users/fnajera-rac-de/following{/other_user}","gists_url":"https://api.github.com/users/fnajera-rac-de/gists{/gist_id}","starred_url":"https://api.github.com/users/fnajera-rac-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnajera-rac-de/subscriptions","organizations_url":"https://api.github.com/users/fnajera-rac-de/orgs","repos_url":"https://api.github.com/users/fnajera-rac-de/repos","events_url":"https://api.github.com/users/fnajera-rac-de/events{/privacy}","received_events_url":"https://api.github.com/users/fnajera-rac-de/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-20T17:57:58Z","updated_at":"2015-04-20T17:57:58Z","closed_at":null,"body":"Hi,\r\n\r\nFirst of all, thanks for the library!\r\nWhile I was implementing my code with this library, I ran into an interesting issue with a piece of code that, at first glance, seems fairly normal:\r\n\r\n```C#\r\nusing (var context = AppDomainContext.Create())\r\n{\r\n    using (var proxy = Remote<MyType>.CreateProxy(context.Domain))\r\n    {\r\n\r\n    }\r\n}\r\n```\r\n\r\nBy the dispose of the inner block, **both** the proxy and the wrapped AppDomain are disposed (and therefore the AppDomain is unloaded), and by the dispose of the outer block, there is an exception because it tries to re-unload the wrapped appdomain (the appdomain wrapper object for the context is different than the appdomain wrapper for the proxy, and it is still not marked as disposed, so it thinks the appdomain is still up and running).\r\n\r\nI've seen the code and the readme file, and I think that the idea is, if you use Remote.CreateProxy, then you shouldn't dispose the context by hand. However, this is counterintuitive in two fronts:\r\n\r\n1. it seems odd to have a IDisposable object (context) that you must NOT dispose, and more importantly,\r\n2. what if you create more than one proxy via Remote.CreateProxy? You then must dispose just one of them, and not the others or the context.\r\n\r\nAnyway, it's not a bug per-se, but I thought it was worth mentioning.\r\n\r\nThanks,\r\n\r\nFernando Nájera"}}