I have a weird problem and couldn't find any solution for it across internet.
This is probably not important for a problem but I prefer to mention that I had two separate projects and decided to combine them into one solution. Both projects were/are simple winform application. They worked separately after compiling: directly in Visual Studio during debugging (no matter in debug or release mode), locally outside debugger and after copying them into some folder on local network.
However after merging them, one of the application stopped working when it is started from the network.
I attached debugger to the already running process and found out that:
frmMain.Designer.vb
in Partial Class frmMain
in Private Sub InitializeComponent()
works properly. This is checked by making a breakpoint at the begin of Sub
and going step-by-step through the code until End Sub
. frmMain.vb
in Public Class frmMain
in Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
is not triggered. After going out from InitializeComponent()
(point 1) code does not enter frmMain_Load
. Main form is shown on the screen with all controls but not initialized/cleaned, without icon etc. Closing child form by clicking on "X" doesn't close the form (normally does). Clicking on cmdClose
button on the same child form closes the form. Button has DialogResult
property set to Cancel
. Form itself has CancelButton
property set to cmdClose
. Pressing ESC
also closes the form.
Private Sub cmdClose_Click(sender As Object, e As EventArgs) Handles cmdClose.Click Me.Dispose() End Sub
Closing the main form (no matter if by "X", cmdClose
button or ESC
) hangs up the application.
Private Sub cmdClose_Click(sender As Object, e As EventArgs) Handles cmdClose.Click Me.Close() End Sub
If I open Windows Explorer and go to the final location of application on shared network drive starting from the mapped drive Y:\\folder
and start application from there - it works.
\\\\server\\share-name\\folder
and start application from there - it doesn't work. target path
to application is defined in one of the two methods. Windows 7, .Net Framework 4.5.
Do you have any clue how to solve it and where the bug is?
I decided to extract the icon from application executable instead of resource like it was before to avoid adding two times the same icon file to the executable: first as an application icon which is added in Project/Properties/Application/Icon and second as an form icon added in Project/Properties/Resources.
The problem is if in any place in code (in my example in Private Sub form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
) you add
Me.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location)
it will not work with UNC paths returning
System.ArgumentException
The filePath does not indicate a valid file or the filePath indicates a Universal Naming Convention (UNC) path.
Error occurs in runtime after form closing. Method
Assembly.GetExecutingAssembly().Location
returns correct path (as string for example \\\\server\\share-name\\folder
) but method
Public Shared Function ExtractAssociatedIcon(filePath As String) As Icon
does not accept UNC path.
To solve this issue 2 clumsy solutions are proposed here and here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.