Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > AddHandler causes FileNotFoundException?
 

AddHandler causes FileNotFoundException?

I have a COM object that I'm using in a VB.NET application. When I create it, my application runs fine:


mMainFunctions = New Mathematics.MainFunctions()


However, if I add a handler to one of the events in the the MainFunction class:


AddHandler mMainFunctions.Message, AddressOf MessageHandler


I get a FileNotFoundException on that particular line of code. The exact same thing happens if I use Handles instead of AddHandler.

This is the exception that I get:


System.IO.FileNotFoundException was unhandled
Message="The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
Source="mscorlib"
StackTrace:
at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie)
at Mathematics.__MainFunctions_EventProvider.add_Message(__MainFunctions_MessageEventHandler )
at Mathematics.MainFunctionsClass.add_Message(__MainFunctions_MessageEventHandler )
at Calculations.CalculatorSetup..ctor() in C:\CODE.NET\Libraries\Calculations\CalculatorSetup.vb:line 18
at Example.Form1.Button1_Click(Object sender, EventArgs e) in C:\CODE.NET\Libraries\Calculations\Example\Form1.vb:line 4
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Example.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


The button click in the stack trace is when I create the form that constructs and sets the handler:


Public Sub New()
InitializeComponent()

mMainMath = New RSW7Math.RSWMathMain()
AddHandler mMainMath.Message, AddressOf Me.bleh
End Sub


I imagine this must have something to do with the code in my COM object, but since all I'm doing is adding a handler, I can't begin to imagine what would cause that to throw a FileNotFoundException.

Thanks ahead of any help.



BlueMikey  Wednesday, January 17, 2007 10:32 PM

Hi,

That's a tough on to diagnose outright.

If you have the original COM component source, try recompiling it and rereferencing the new version in your .net application.Maybe something has been corrupted along the lines so hopefully this 'remapping' exercise will resolve any problems.

iProgrammer.co.uk  Monday, January 22, 2007 10:42 AM
Hard to guess what might be wrong with your COM component. Perhaps it just generates the wrong HRESULT return value in its implementation of IConnectionPoint.Advise(). The proper error code for "event not available" is 0x80040202, sorta close...
nobugz  Sunday, January 21, 2007 6:02 PM

Hi,

That's a tough on to diagnose outright.

If you have the original COM component source, try recompiling it and rereferencing the new version in your .net application.Maybe something has been corrupted along the lines so hopefully this 'remapping' exercise will resolve any problems.

iProgrammer.co.uk  Monday, January 22, 2007 10:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Auto Scrolling a DataGrid
• Status bar
• ListBoxes selection issue
• Data Queues
• Sending and recieving information from ports
• SpellCheck
• Advice on processing a webpage please!
• Place CheckListBox inside DatagridView
• How to run Java in an application
• Image Header file missing in byte array ?