Hi All,
In my UI Layer I am raising the Exception Divisible by Zero.
In Catch block of UI Layer I am calling the Business layer function to write this exception into Event Viewer
After the Exception writes into the Event viewer the control come back to UI Layer of Catch block.
When I am getting the error like “Exception has been thrown by the target of an invocation.”
If you know the solution for this problem, please reply to this mail.
I am using
.Net 2.0, Application Block 2.0 and XP Professional
See the Following Code
Business Layer
public interface ICommonFunctions
{
void LogErrInToFile(Exception ex);
}
public class CommonFunctions : MarshalByRefObject, ICommonFunctions
{
public bool LogErrInToFile(Exception ex)
{
bool boolError = ExceptionPolicy.HandleException(ex, "ExceptionPolicy");
}
}
UI Layer
try
{
int i = 1;
int j = 0;
int k = i / j;
}
catch (Exception ex)
{
bool boolError = objCF.LogErrInToFile(ex); //Error occurs after the control comes from Business layer.
}
finally
{
}
Error
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
Server stack trace:
at System.RuntimeMethodHandle._SerializationInvoke(Ob ject target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.RuntimeMethodHandle.SerializationInvoke(Obj ect target, SignatureStruct declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.Reflection.RuntimeConstructorInfo.Serializa tionInvoke(Object target, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.Complet eISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.FixupSp ecialObject(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixup s()
at System.Runtime.Serialization.Formatters.Soap.Objec tReader.Deserialize(HeaderHandler handler, ISerParser serParser)
at System.Runtime.Serialization.Formatters.Soap.SoapF ormatter.Deserialize(Stream serializationStream, HeaderHandler handler)
at System.Runtime.Remoting.Channels.CoreChannel.Deser ializeSoapResponseMessage(Stream inputStream, IMessage requestMsg, Header[] h, Boolean bStrictBinding)
at System.Runtime.Remoting.Channels.SoapClientFormatt erSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
at System.Runtime.Remoting.Channels.SoapClientFormatt erSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgData, Int32 type)
at Thames.OSS.Interfaces.ICommonFunctions.LogErrInToF ile(Exception ex)
at OSSThickClientProject.ProfileManagement.profileMan agement_Load(Object sender, EventArgs e) in D:\GISADS3\OSSThickClientProject\ProfileManagement .cs:line 63
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessa ge(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at OSSThickClientProject.Program.Main() in D:\GISADS3\OSSThickClientProject\Program.cs:line 20
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Thanks in advance.
Regards
Rajaram.