Ok, I debugged and I can see my exception thrown and then the next
thing is that TargetInvocationException is caught.  I looked at the
stack trace of the exception and here is what is says:
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target,
Object[] arguments, SignatureStruct& sig, MethodAttributes
methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object
[] arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[]
parameters)
   at NHibernate.Proxy.Poco.Castle.CastleLazyInitializer.Intercept
(IInvocation invocation) in C:\Users\epitka\UltiMod\NHibernate
\NHibernate-2.0.1.GA-src\src\NHibernate\Proxy\Poco\Castle
\CastleLazyInitializer.cs:line 60


Looking at the line sixty it does this.

if (invocation.ReturnValue == InvokeImplementation)
                                        {
                                                invocation.ReturnValue = 
invocation.Method.Invoke
(GetImplementation(), invocation.Arguments);
                                                return;
                                        }

which will invoke my property setter that throws ValidationException,
which is then caught in this block

catch (TargetInvocationException tie)
                        {
                                // Propagate the inner exception so that the 
proxy throws the same
exception as
                                // the real object would
                                throw 
ReflectHelper.UnwrapTargetInvocationException(tie);
                        }

which does not really unwrap it at all, It just returns regular
exception with my exception being inner one.





On Dec 16, 12:04 pm, "Richard \(Google\)" <[email protected]>
wrote:
> Hi epitka,
>
> Can you get the full stack trace for the exception that is thrown?
>
> The line:
> ''System.Reflection.TargetInvocationException' occurred in mscorlib.dll'
> suggests (from mscorlib.dll) that the error you are getting is coming from
> the .Net framework - not from NHibernate.
>
> The code for CastLazyInitalizer catches any exceptions and unwraps them - so
> it shouldn't change the original exception thrown (see line 
> 74):http://nhibernate.svn.sourceforge.net/viewvc/nhibernate/branches/2.0....
>
> Regards,
>     Richard
>
> --------------------------------------------------
> From: "epitka" <[email protected]>
> Sent: Tuesday, December 16, 2008 5:46 PM
> To: "nhusers" <[email protected]>
> Subject: [nhusers] Re: CastleLazyInitializer does not propagate exceptions
> correctly
>
>
>
> > Ok, here is what I see in output window
>
> > 'w3wp.exe' (Managed): Loaded 'DynamicProxyGenAssembly2'
> > 'w3wp.exe' (Managed): Loaded 'CastleDynProxy2.dll'
> > 'w3wp.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\ISymWrapper
> > \2.0.0.0__b03f5f7f11d50a3a\ISymWrapper.dll'
> > A first chance exception of type
> > 'dnnSphere.Exceptions.ValidationException' occurred in
> > dnnSphere.Meta.DLL
> > A first chance exception of type
> > 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
>
> > and I am catching it like this. I have a workaround where I look at he
> > inner exception.
>
> > // *** Handles any  errors that are raise from the property setters
> >                catch (ValidationException ve)
> >                {
> >                    this.HandleUnbindingError(Item, new
> > ValidationErrorException(ve.Message));
> >                }
> >                catch (Exception ex)
> >                {
> >                    //this is a hack to NHibernate proxy exceptions
> >                    if (ex.InnerException is ValidationException)
> >                    {
> >                        this.HandleUnbindingError(Item, new
> > ValidationErrorException(ex.InnerException.Message));
> >                    }
> >                    else
> >                    {
> >                        this.HandleUnbindingError(Item, ex);
> >                        ResultFlag = false;
> >                    }
>
> >                }
>
> > On Dec 16, 7:34 am, epitka <[email protected]> wrote:
> >> Will do, it will take several hours before I get back to it. Got to
> >> take kids to school.
>
> >> On Dec 16, 7:16 am, "Richard \(Google\)" <[email protected]>
> >> wrote:
>
> >> > Can you post a stack trace?
>
> >> > From: first last
> >> > Sent: Tuesday, December 16, 2008 1:02 PM
> >> > To: [email protected]
> >> > Subject: [nhusers] Re: CastleLazyInitializer does not propagate
> >> > exceptions correctly
>
> >> > 2.0
>
> >> > ---------------------------------------------------------------------------
> >> >  -----
> >> > From: Richard (Google) <[email protected]>
> >> > To: nhusers <[email protected]>
> >> > Sent: Tuesday, December 16, 2008 4:30:44 AM
> >> > Subject: [nhusers] Re: CastleLazyInitializer does not propagate
> >> > exceptions correctly
>
> >> > Hi epitka,
>
> >> > What version of NH are you using?
>
> >> > This was sorted for V2.0 I think.
>
> >> > Regards,
> >> > Richard
>
> >> > --------------------------------------------------
> >> > From: "epitka" <[email protected]>
> >> > Sent: Monday, December 15, 2008 11:07 PM
> >> > To: "nhusers" <[email protected]>
> >> > Subject: [nhusers] CastleLazyInitializer does not propagate exceptions
> >> > correctly
>
> >> > > This code in CastleLazyInitializer returns generic Exception with a
> >> > > generic "Target of invoication ..." message. I am rasing
> >> > > ValidationException in my code yet I cannot catch it as
> >> > > ValidationException only as Exception. My exception is actually in
> >> > > innerException. How am I supposed to catch custom exceptions?
>
> >> > > /// <summary>
> >> > > /// Invoke the actual Property/Method using the Proxy or instantiate
> >> > > the actual
> >> > > /// object and use it when the Proxy can't handle the method.
> >> > > /// </summary>
> >> > > /// <param name="invocation">The <see cref="IInvocation"/> from the
> >> > > generated Castle.DynamicProxy.</param>
> >> > > public virtual void Intercept(IInvocation invocation)
> >> > > {
> >> > > try
> >> > > {
> >> > > if (_constructed)
> >> > > {
> >> > > // let the generic LazyInitializer figure out if this can be
> >> > > handled
> >> > > // with the proxy or if the real class needs to be initialized
> >> > > invocation.ReturnValue = base.Invoke(invocation.Method,
> >> > > invocation.Arguments, invocation.Proxy);
>
> >> > > // the base LazyInitializer could not handle it so we need to
> >> > > Invoke
> >> > > // the method/property against the real class
> >> > > if (invocation.ReturnValue == InvokeImplementation)
> >> > > {
> >> > > invocation.ReturnValue = invocation.Method.Invoke
> >> > > (GetImplementation(), invocation.Arguments);
> >> > > return;
> >> > > }
> >> > > else
> >> > > {
> >> > > return;
> >> > > }
> >> > > }
> >> > > else
> >> > > {
> >> > > // TODO: Find out equivalent to CGLIB's 'method.invokeSuper'.
> >> > > return;
> >> > > }
> >> > > }
> >> > > catch (TargetInvocationException tie)
> >> > > {
> >> > > // Propagate the inner exception so that the proxy throws the same
> >> > > exception as
> >> > > // the real object would
> >> > > throw ReflectHelper.UnwrapTargetInvocationException(tie);
> >> > > }
> >> > > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to