rbellamy/NHibernate.ByteCode.Castle — pull request #1 by craigfowler (2012-08-10 16:44:02+00:00)
Title: Fixes a bug that causes an unhelpful NullReferenceException when running under Mono

...o

If running this library under a Mono environment instead of .NET framework
and a TargetInvocationException is caught within
LazyInitializer.Intercept(IInvocation) then you will see a stack trace something
like:

System.NullReferenceException: Object reference not set to an instance of an object
at NHibernate.ByteCode.Castle.LazyInitializer.Intercept(IInvocation invocation)

This is because it makes use of reflection to invoke the private/internal method
'InternalPreserveStackTrace' of the Exception type. This is undocumented
functionality and not a part of the API. This method does not exist within the
Mono framework.

* This commit simply null-checks that method and - if it does not exist - skips
attempting to call it. Whilst we may lose the stack trace as a result, we
still preserve some of the original exception and avoid throwing a completely
unhelpful exception.