philiplaureano / LinFu

A framework that adds mixins, inversion of control, DbC, and other language features to the Common Language Runtime.
http://www.codeproject.com/KB/cs/LinFuPart1.aspx
206 stars 30 forks source link

IndexOutOfRangeException when calling proxy object's intercepting method #21

Closed caprofage closed 12 years ago

caprofage commented 12 years ago

We have an error with following description when using proxy of our interfaces generated by Linfu.Core 2.3 in website application.

Description from EventLog:

Exception information: Exception type: IndexOutOfRangeException Exception message: Index was outside the bounds of the array.

Request information: Request URL: http://[OUR_SITE]/xxx Request path: /path User host address: xx.xx.xx.xx User: 1586068 Is authenticated: True Authentication Type: Forms Thread account name: IIS APPPOOL\App

Thread information: Thread ID: 50 Thread account name: IIS APPPOOL\App Is impersonating: False Stack trace: at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value) at LinFu.AOP.Cecil.IgnoredInstancesRegistry.AddInstance(Object target) at LinFu.Proxy.IBlockServiceProxy-05990fd14dbb49659cd0ebe8d8e66327.System.IDisposable.Dispose() at MyProj.ContactList.ContactListAdapter.GetBlockedUsers(Member owner) in C:!Projects\xxx\ContactListAdapter.cs:line 174

Error appears only with Linfu.Core version 2.3 and only in applications with a great level of concurrent calls.

IBlockServiceProxy is a proxy of our interface. When we generate proxy by ProxyFactory object we mixin additional IDisposable interface like this:

_proxyFactory.CreateProxy(_interceptor, typeof(IDisposable))

And error occures when Dispose is called implicitly in using operator. In interceptor we have some logic for intercepting dispose call.

philiplaureano commented 12 years ago

I just patched the IgnoredInstancesRegistry class now. Try it again and let me know if it fixes the issue.

caprofage commented 12 years ago

Thx for quick response and fix. We will test an issue fix asap.

PS: I think it is not necessary to introduce target.GetHashCode call into lock scope. But I could be wrong.