I would really appreciate your help here. My application is as follows,
Operating System: Windows 7 64 Bit OS
Visual Studio: VS 2012
Application: VB.Net running on .Net framework 4
In my application, I have a button which calls my custom method ‘Select_Batch_File()’. Once this button is clicked it supposes to open the ‘OpenFileDialog’ to select particular file. This works fine on my machine with above configuration however; on some of my colleagues machine (with same configuration above) this does not work and fails without any exception. I have collected the thread dump from my colleague’s machine which is as follows,
======================
Log Name: Application
Source: .NET Runtime
Date: 3/18/2013 1:54:19 PM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Description:
Application: Visual AEEMS.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Windows.Forms.FileDialogNative+IFileDialog.Show(IntPtr)
at System.Windows.Forms.FileDialog.RunDialogVista(IntPtr)
at System.Windows.Forms.FileDialog.RunDialog(IntPtr)
at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
===============
I followed a solution from MSDN forum wherein users were asked to uncheck the option in visual studio > Tools > Options > Debugging > ‘Suppress JIT optimization on module load (Managed only)’ but had no luck.
Here is my code
Sub Select_Batch_File()
Try
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.AutoUpgradeEnabled = False
Full_Path = "" : file_name = ""
OpenFileDialog.Multiselect = False
Try
<<Here I am getting exception>>
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
EMS_Dir = OpenFileDialog.FileName 'get the path
EMS_Dir = StrReverse(EMS_Dir) 'reverse the string
EMS_Dir = Mid(EMS_Dir, InStr(EMS_Dir, "\"), Len(EMS_Dir)) 'extract from the first slash
EMS_Dir = StrReverse(EMS_Dir) 'reverse it again
'file_name = OpenFileDialog.SafeFileName
file_name = OpenFileDialog.FileName
End If
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
End Sub
Please advice.
You will get an exception if you set the AutoUpgradeEnabled property. Don't know why, but there it is.
Related
I am working on a program in VS 2017 coding in VB.Net. The program downloads Web pages using Net.WebClient.DownloadString and then parses the data. It worked fine for a year or more then one day I started getting an exception when downloading the pages.
The ex.Message is: 'The underlying connection was closed: An unexpected error occurred on a send.'
The ex.InnerException.Message is: 'Unable to write data to the transport connection: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.'
I have VS 2017 installed on 2 other PC's at this location and on 1 at another location. They all continue to run the code without exception. It is only an issue on this PC.
The code is below (I changed the Web address but it fails for any valid URL).
Any ideas why this fails on my main PC only?
Public Function DownloadData() As Boolean
Dim strURL As String = "https://www.google.com/"
Dim strOutput As String
Try
Using WC As New Net.WebClient
strOutput = WC.DownloadString(strURL)
If strOutput.Length > 0 Then
If ParseData(strOutput) = True Then
Return True
End If
Else
Return False
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.InnerException.Message, "Error")
End Try
End Function
I have a VB.Net windows forms application which is working fine in windows 7 environment.
Now, I want to upgrade to windows 10. So I have started to test my application in windows 10 server machine.
I am getting an Exception (Exception from HRESULT:0X800A03EC) while saving a dynamically generated file in one of the folders on server.
I have identified the issue is not with the permissions.
'getting exception at this line of code.
xlApp.Workbooks(1).SaveAs(filename , xl.XlFileFormat.xlHtml)
Code for reference:
Private Sub VierwInBrowser(ByVal xlApp As xl.Application)
Dim fileName As String = String.Format("{0}\{1}", "C:\Data", GetUniqueFileName())
Try
xlApp.Workbooks(1).SaveAs(fileName, xl.XlFileFormat.xlHtml)
Catch ex as Exception
Messagebox.Show(ex.Message)
End Try
xlApp.Quit()
xlApp = Nothing
GC.Collect()
browser.Visible = True
browser.Navigate(fileName)
browser.BringToFront()
End Sub
I have identified that the issue is with converting the excel sheet to html page in windows 10.
For this I have found a solution at https://support.microsoft.com/en-in/help/922850/error-message-in-office-when-a-file-is-blocked-by-registry-policy-sett
I have a VB.Net application in which I have a general method to open documents that exist on the local drive using system.diagnostics.process.
Public Shared Function OpenFileWithProcess(ByVal lsFileNameWithPath As String, Optional ByVal lPrintOption As PrintOutputOption = PrintOutputOption.Preview)
Try
Select Case lPrintOption
Case PrintOutputOption.Preview
Dim P As System.Diagnostics.Process
P = Process.Start(lsFileNameWithPath)
If Not P Is Nothing Then
Dim handle As IntPtr = P.Handle
SetForegroundWindow(handle)
End If
Case PrintOutputOption.Print
Dim Proc As New Process
Proc.StartInfo.FileName = lsFileNameWithPath
Proc.StartInfo.UseShellExecute = True
Proc.StartInfo.Verb = "Print"
Proc.Start()
End Select
Catch ex As Exception
If oSQL.Key_Developer Then
Stop
End If
Throw ex
End Try
End Function
On some computers that have Windows8 and OFfice2010, this method will not open an Excel file without Excel being open first. Instead it will error with "Run-Time Error 2147467259 (80004005). An error occurred in sending the command to the application".
If Excel is open prior to the method call, then the file opens just fine.
Some additional environment info:
- VB.NET application compiled to .Net Framework 4
- Application is deployed on Windows 7, 8 and 8.1
I could trap for the error and try to start the process again using the Excel session that hangs open after the error but I'm wondering if someone can tell me or help me figure out what is going on here.
Thank you for your time.
I keep getting an error:
System.NullReferenceException: Object reference not set to an instance
of an object.
Everytime I run the application outside the IDE, but for some magical reason, it works fine inside the IDE. I am definitely sure the error is caused by this code as the app ran smoothly when I removed it:
Public Function GetCommonFolder() As String
On Error GoTo ErrH
Dim winPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Dim commonfolderpath As String
commonfolderpath = Replace(winPath & "\MyApp Data", "\\", "\")
If My.Computer.FileSystem.DirectoryExists(commonfolderpath) = False Then
System.IO.Directory.CreateDirectory(commonfolderpath)
End If
GetCommonFolder = commonfolderpath
Exit Function
ErrH:
GetCommonFolder = ""
Msgbox("Error retrieving common folder")
End Function
Does anyone here know what is causing this annoying problem?
It seems like the user that you run the program on outside the IDE doesn't have access to the common application data folder. Try executing it by "Run as administrator". Are you running on Windows Vista or newer? Maybe you have to require UAC elevation?
I'm working on a project for school in which a dll is loaded.
The dll that is loaded is a bridge between my program and the Twincat System Manager which forms the bridge between the computer and a PLC via the local network.
I need to read Variables trough this whole chain from the plc to my program.
This is the way I do this:
Public Function adsReadReal(ByVal Variabelenaam As String) As Single
Dim ds = New TwinCAT.Ads.AdsStream(4 * 8) ' new data stream
Dim br = New System.IO.BinaryReader(ds) 'new binary
Dim hVar = New Integer
Try
ConState(1)
tcclient = New TcAdsClient
ConState(2)
tcclient.Connect(Form1.amsAdress, 801) 'connects the tcclient to the PLC
hVar = tcclient.CreateVariableHandle(Variabelenaam) 'creats a handle for the variable
tcclient.Read(hVar, ds) 'read it
ConState(5)
Return br.ReadSingle() 'convert it from binary to readable for vb
Catch ex As Exception
ConState(0)
PrintEx(ex) 'print out the exception
finally
tcclient.Dispose() 'make the object stop being used to prevent a lingering connection
End Try
Return False
End Function
Now the program loads a dll called TwinCAT.ADS.dll at the start of the connection module. If the Twincat system manager is running the program ends normally, but when it is not it crashes and gives me this error:
System.DllNotFoundException was unhandled
Message="Kan DLL tcadsdll.dll niet laden: Kan opgegeven module niet vinden. (Uitzondering van HRESULT: 0x8007007E)"
Source="TwinCAT.Ads"
TypeName=""
StackTrace:
bij TwinCAT.Ads.Internal.TcAdsDllWrapper.TcAdsDll.AdsAmsUnRegisterRouterNotification()
bij TwinCAT.Ads.Internal.TcAdsDllWrapper.AmsUnRegisterRouterNotification(Boolean
throwAdsException)
bij TwinCAT.Ads.Internal.TcLocalSystem.Dispose(Boolean disposing)
bij TwinCAT.Ads.Internal.TcLocalSystem.Finalize()
which is roughly translated to:
Cannot load DLL tcadsdll.dll: Cannot find given module. (Exception at
HRESULT: 0x8007007E)
This is not a dll that I have imported, so it must be from the TwinCAT.ADS.dll
How can I prevent the program from throwing this error at me and instead close the program peacefully? I have tried to catch all the exceptions of every dll related operation possible.
Also the source is on Bitbucket. I will make it public on request.
Some links on the official but quite unhandy Beckhoff site:
http://infosys.beckhoff.com/espanol.php?content=../content/1034/tcquickstart/html/tcquickstart_samplevisualbasicnet.htm&id=10449
Edit:
Apparently using tcclient.dispose() causes the error since the finnaly statement was use instead of just after the try block
Edit: This currently catches the exception but it does not handle it.
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf MyHandler
Dim tick As Byte = 0
Sub MyHandler(sender As Object, args As UnhandledExceptionEventArgs)
Dim ex As Exception = DirectCast(args.ExceptionObject, Exception)
MsgBox("exception tick" & Str(tick))
tick = tick + 1
PrintEx(ex)
End Sub
Edit:
The exception isn't caught properly because in vs2008 a couple of errors occurs but the tick appears after I press F5 (continue)
When the program is run directly, I only see 1 Tick. Then windows gives an error.
Did you try an unhandled exception handler?
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf MyHandler
Sub MyHandler(sender As Object, args As UnhandledExceptionEventArgs)
Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
Console.WriteLine("MyHandler caught : " + e.Message)
End Sub