Click here to Skip to main content
15,915,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody again,
In my wpf application, i have a button to get data from some device. When i "click" the button, i get the next exception.

"An unhandled exception of type 'JKKR.Core.Exceptions.EIncorrectDeviceId' occurred in PresentationFramework.dll"

Here is a part of my code:
VB
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button.Click
              

SpyModem.GetSatelliteMemory(Sate, "0256", 1, memory)
 TextBox1.Text = Sate

    End Sub


Details: My application is composed by many Windows (formulary). So, In some cases, I must call another window (formulary) by clicking on a button.
When i Click the Button, the program show the line where is the problem:

VB
    Public Sub Button_Acqui(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

       
        Dim fenetreAcqui As New Acquisition()
        fenetreAcqui.Fenetre_main = Me.Fenetre_main


           fenetreAcqui.ShowDialog()
End Sub

The last methode open a new window. That window is within of ViewBox.
The problem is in the next line:
VB
fenetreAcqui.ShowDialog()


Note: I have a DLL Library.
Somebody can give some clue about this problem? is something about parent and child?
Posted
Comments
Pheonyx 1-Aug-13 10:35am    
What is "Acquisition()" ? is that a form?
If so what code is in it's "Load" event?
alonetmr 1-Aug-13 14:40pm    
hi,
In fact, "Acquisition()" is a class.
[no name] 1-Aug-13 10:47am    
This should give you some idea http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn

1 solution

First of all, run it under the debugger and find out where the exception was thrown. Put a breakpoint before it happens and use the VS "Watch" window to inspect variable. Consult the device documentation on the parameters required for the call in question and other requirements. Show VS "Call stack" windows (under the "Debug" menu) to find out the stack and the path of the propagation of the exception. You will see all what happens starting from the root cause of it, from the initial UI event, for example. Fix the problem.

You need to catch all exceptions on the top stack frame of each stack. Don't catch too much, keep it to necessary minimum, where you really know what to do with exception handling. UI has a special feature to catch all exception in the top even handling loop. For WPF, this is done via the Application.DispatcherUnhandledException event:
http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx[^].

You should always do that. In case of some problem, you can alternatively add additional code for the research: when some exception is caught, output its stack trace:
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx[^].

This is just a string, and it will show you the same exception propagation path, as with the "Call Stack" used under the debugger. In rare cases when debuggers is hard to use, you can simply log exception information (with stack trace) and still dig out the problem. For logging, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

—SA
 
Share this answer
 
Comments
Maciej Los 1-Aug-13 15:36pm    
Good advice!
+5
Sergey Alexandrovich Kryukov 1-Aug-13 17:27pm    
Thank you, Maciej.
—SA
alonetmr 2-Aug-13 3:20am    
Thank you Sergey,
But i'm not an computer expert, so, for me is complicated to understand your last solution. Honestly is hard to me apply that solution to my project.
By the way, you have a simply solution?
Thank you
Sergey Alexandrovich Kryukov 2-Aug-13 10:03am    
This is not a solution, but two solutions: the debugger and the logging. None of them is complicated or simple. Second one is just the alternative if the first one does not work. It's not that can be a simple or a complex solution, it's just your problem can be easier or harder, and it depends on how good developer you are.

That's why your question "you have a simple solution" makes no sense at all. I'm trying to give you the best advice. If you cannot apply it, it means that you created a problem that you cannot solve in principle. "Simpler" solution won't help. If you cannot solve the problem, you should probably write a simpler project.

Also, you should understand that you will have to solve your problems by yourself. And advice or resolution of some particular problem does not mean that someone will dig into your problem all the time. You will need to learn debugging by yourself.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900