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.x/nhibernate/src/NHibernate/Proxy/Poco/Castle/CastleLazyInitializer.cs?revision=3419&view=markup 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 -~----------~----~----~----~------~----~------~--~---
