DataPortalMethodCache bug - keyed on object name not qualified enough

DataPortalMethodCache bug - keyed on object name not qualified enough

Old forum URL: forums.lhotka.net/forums/t/11549.aspx


Jaans posted on Wednesday, August 22, 2012

Hi Rocky

We've been hunting an issue that's been eluding us for days now, but have eventually found the culprit. It turns out that the DataPortalMethodCache is returning the methods from cache, for data portal methods from other classes under certain circumstances.

The reason for this is because the MethodCacheKey that is used in the DataPortalMethodCache only looks at the objectType.Name and not objectType.FullName.

Note, this issue only shows up if you have classes with the same name (and data portal methods), as in our case where we have many classes with the same name but under different namespaces or some are nested classes.

This cache "mishit" wouldn't be much of a problem, but for us it's rather big because we have differing Transactional attributes for different classes. This is exactly where the bug came into play for us - with methods that were not attributed as being TransactionScope were actually being treated as if they were, because the cache hit returned the entry for a different (but same named) class that actually did have the transactional attribute applied.

I'm suspecting that the simple fix is to use objectType.FullName instead of just .Name, but you may have reservations, or there may be knock on effects / changes. In our case the offending line of code is from the method "Csla.Server.DataPortalMethodCache.GetMethodInfo( Type objectType, string methodName, params object[] parameters) { ... }" (from where the MethodCacheKey instance is created. Refer attachment.

Drop me an email if you need more information or for me to create a dummy project to demonstrate the issue.

Thanks,
Jaans

Copyright (c) Marimer LLC