Open raster file error: A Debugger is attached to w3wp exe but not configured - vb.net

I have written a vb.net function to open a raster file. The function is as follows:
Public Function OpenRaster(ByVal directoryName As String, ByVal fileName As String) As IRaster
Dim workspaceFactory As IWorkspaceFactory
Dim rasterWorkspace As IRasterWorkspace
Dim rasterDataset As IRasterDataset = Nothing
Try
workspaceFactory = New RasterWorkspaceFactory
ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()
rasterWorkspace = TryCast(workspaceFactory.OpenFromFile(directoryName, 0), IRasterWorkspace)
rasterDataset = rasterWorkspace.OpenRasterDataset(fileName)
Catch e As Exception
End Try
Dim pRasterLayer As IRasterLayer = New RasterLayer()
pRasterLayer.CreateFromDataset(rasterDataset)
Dim pRaster As IRaster = Nothing
pRaster = pRasterLayer.Raster
Return pRaster
End Function
The above function is throwing below error in TryCast statement :
A Debugger is attached to w3wp exe but not configured to debug this unhandled exception. To debug this expression detach the current debugger.
I searched on google also, some suggestions were to enable 32-bit in IIS application pool, but enabling this also is not making the code work

Related

vb.net runs gpg.exe step of job runs ok from PC but not from SQL Server Agent schedule

Everything worked great from my Visual Studio on my PC running this from the Start button. When I build the executable and copied the executable to the production box and scheduled the job via SQL Server Agent on the production machine – everything worked fine to create the file, but the encryption bit does not work.
The gpg.exe is here on the production server: \sql2014\c$\Program Files (x86)\GnuPG\bin
The gpg is here on my PC: C:\Program Files (x86)\GnuPG\bin
The filename.csv gets created in the proper location ok - I tested with both these names
Dim Extract_File As String = “\sql2014\e$\Extracts\ProgramName\filename.csv”
‘Dim Extract_File As String = “E:\Extracts\ProgramName\filename.csv” ‘do to this from my PC I had to change the E: to a C:
This line calls the function:
FileEncrypted = Encrypt_File(Extract_File, Batch_Timestamp)
Private Function Encrypt_File(File_To_Encrypt As String, Batch_Timestamp As Date)
On Error GoTo Encrypt_File_Error
Dim Success As Boolean = False
Dim sourceName As String = File_To_Encrypt
Dim gpgProcess = New Process()
‘Test with working directory - no effect
‘gpgProcess.StartInfo.UseShellExecute = False
'gpgProcess.StartInfo.WorkingDirectory = "\\sql2014\c$\Program Files (x86)\GnuPG\bin\"
‘gpgProcess.StartInfo.FileName = "gpg.exe"
gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bin\gpg.exe ‘This works from my PC
‘gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bn\gpg.exe ‘If I change this path took the “i” out of bin I get an error: The system cannot find the file specified
gpgProcess.StartInfo.UseShellExecute = False
gpgProcess.StartInfo.CreateNoWindow = True
gpgProcess.StartInfo.Arguments = "--batch --yes --recipient reciptname --encrypt " & sourceName
gpgProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
gpgProcess.Start()
gpgProcess.WaitForExit()
If FileExists(sourceName & ".gpg") Then
Success = True
End If
Encrypt_File_Exit:
On Error Resume Next
‘gpgProcess.WaitForExit() moved this up to
gpgProcess.Close()
Return Success
Exit Function
Encrypt_File_Error:
Error_Handler("SomeModule.vb", "Encrypt_File", Err, System_Output, Batch_Timestamp)
Resume Encrypt_File_Exit
End Function
Any suggestions for how I can resolve this. When it worked on my PC it creates a filename.csv.gpg in the same directory as filename.csv. On the production server it does not create the gpg and it does not give a visible error message either.
This is how I solved this issue. I Installed the OpenPgpLib from the NuGet Package Manager and re-wrote this Function as shown here.
I created the .asc file from the Kleopatra tool and saved it in the location used in the pubkey in the code bit below. The OpenPgp is from the package.
Private Function Encrypt_File(File_To_Encrypt As String, Log_File As String, Batch_Timestamp As Date)
Dim Success As Boolean = False
Dim encryptthis As String = File_To_Encrypt
Dim thisencrypted As String = File_To_Encrypt & ".gpg"
Dim pubkey As String = "\\sql2014\c$\Data_Programs\MyDirectory\<thepublickeyfile>.asc"
Try
OpenPgp.EncryptFile(encryptthis, thisencrypted, pubkey, False, False)
If FileExists(thisencrypted) Then
Success = True
End If
Catch ex As Exception
App_Logger(Log_File, ex.StackTrace.ToString(), System_Output, Batch_Timestamp)
Success = False
End Try
Return Success
End Function

Extracting `dll` files from the Resources after they been added using CodeDOM in VB.Net

I'v seen a lot of answers here on stackoverflow, but none of them help me with exactly what i need and almost all of them in C# when i need VB, so i hope someone will help me with my problem, which is this :
I have compiled a exe file in vb.net using CodeDOM, and i added two dll file to its resources and that worked just fine and you can even notice that the size of the exe has increase after adding the resources, but when i run the exe file like that My.Resources.Touchless, it gives me an error saying that
"Resources" is not a member of "My".
And what i need is to read these dll files from the compiled exe file and then extract them using File.WriteAllBytes()..., if i didn't try to extract the files from the resources and instead of that i copied them manually to the executable path, the application will work perfectly, so the problem is just with trying to call the dll files from the resources.
Here is some code :
Public Shared Function Compile(ByVal Output As String, ByVal Source As String, ByVal Icon As String, ByVal resources As String) As Boolean
Dim Parameters As New CompilerParameters()
Dim cResults As CompilerResults = Nothing
Dim Compiler As CodeDomProvider = CodeDomProvider.CreateProvider("VB")
Parameters.GenerateExecutable = True
Parameters.TreatWarningsAsErrors = False
Parameters.OutputAssembly = Output
Parameters.MainClass = "MyNamespace.MainWindow"
Parameters.EmbeddedResources.Add(Path.GetTempPath & "TouchlessLib.dll")
Parameters.EmbeddedResources.Add(Path.GetTempPath & "WebCamLib.dll")
Parameters.ReferencedAssemblies.AddRange(New String() {"System.dll", "System.Drawing.dll", "System.Windows.Forms.dll", "System.Management.dll", Path.GetTempPath & "TouchlessLib.dll"})
Parameters.CompilerOptions = "/platform:x86 /target:winexe"
If Not String.IsNullOrEmpty(Icon) Then
File.Copy(Icon, "icon.ico")
Parameters.CompilerOptions += " /win32icon:" & "icon.ico"
End If
cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
If cResults.Errors.Count > 0 Then
For Each compile_error As CompilerError In cResults.Errors
Dim [error] As CompilerError = compile_error
Console.Beep()
MsgBox("Error: " & [error].ErrorText & vbCr & vbLf & [error].Line)
Next
Return False
End If
If Not (String.IsNullOrEmpty(Icon)) Then
File.Delete("icon.ico")
End If
Return True
End Function
When i call them from the compiled exe file like this :
File.WriteAllBytes(Application.StartupPath & "\TouchlessLib.dll", My.Resources.TouchlessLib)
File.WriteAllBytes(Application.StartupPath & "\WebCamLib.dll", My.Resources.WebCamLib)
... i get the following error message :
"Resources" is not a member of "My".
Try adding this class:
Imports System.Dynamic
Imports System.Reflection
Public Class DynamicResources
Inherits DynamicObject
Public Overrides Function TryGetMember(binder As GetMemberBinder, ByRef result As Object) As Boolean
Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim resouceNames As String() = asm.GetManifestResourceNames
For Each s As String In resouceNames
Dim name As String = IO.Path.GetFileNameWithoutExtension(s)
Dim Manager As New Resources.ResourceManager(name, asm)
Try
Dim resource = Manager.GetObject(binder.Name)
If Not resource Is Nothing Then
result = resource
Return True
End If
Catch ex As Exception
End Try
Next
Return False
End Function
End Class
You can use it like this:
Dim root as string=Application.StartupPath
File.WriteAllBytes(Path.Combine(root, "TouchlessLib.dll"), DynamicResources.TouchlessLib)
File.WriteAllBytes(Path.Combine(root, "WebCamLib.dll"), DynamicResources.WebCamLib)
The My namespace and any associated functionality is created via auto-generated code. Since your code is now the code generator and not the IDE, you will not have those niceties unless your code provides it.
To extract an embedded resource, you need to include code similar to the following in the source code you are compiling with CodeDOM.
Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim resouceNames As String() = asm.GetManifestResourceNames
For Each s As String In resouceNames
Dim fi As New FileInfo(s)
Using strm As Stream = asm.GetManifestResourceStream(s)
Using fs As Stream = fi.Create()
strm.CopyTo(fs)
End Using
End Using
Next
Make sure that you also include:
Imports System.Reflection
Imports System.IO
This code retrieves the executing Assembly obtains an array of embedded resource names. It then calls GetManifestResourceStream method to get the named resource as a stream. This stream is copied to a file stream.
Modify the example to suite your needs.
Note that I have not included any error checking/handling in this example. Anything dealing with IO should have some error handling.
Edit:
Based on the comment below, it appears that only a copy/paste type answer will do for the OP.
Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim resourceName As String
Dim fi As FileInfo
resourceName = "TouchlessLib.dll"
fi = New FileInfo(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, resourceName))
Using strm As Stream = asm.GetManifestResourceStream(resourceName)
Using fs As Stream = fi.Create()
strm.CopyTo(fs)
End Using
End Using

Writing to Command Line Not Working

An application I need to use (USB capture utility) has a .cmd version that I can call from my Visual Basic code. I am able to launch the application and put it in "command line mode" like this:
Public Class MyClass
Dim StreamWriteUtility As System.IO.StreamWriter
Dim StreamReadUtility As System.IO.StringReader
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
Public Sub StartUSBCapture(ByVal DataStorageLocation As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As New Process
ProcessInfo = New ProcessStartInfo("C:\FW_Qualification_Suite\data-center-windows\data-center\bin\datacenter.cmd", "-c ")
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = False 'Must be changed if redirect set to True
ProcessInfo.RedirectStandardInput = True
Process = Process.Start(ProcessInfo)
SWUtility = Process.StandardInput
While True
SWUtility.WriteLine("run") 'Looping for test to ensure this isn't a timing issue
End While
End Sub
End Class
This launches the application and opens a separate command line window that should accept further commands (i.e., capture, run, stop, etc). However, I am having trouble getting those subsequent commands to show up in the command line window. I've tried redirecting the standard input of the process, but still nothing shows up in the console window.
Can anyone tell how I'm supposed to actually get these commands from my Visual Basic program into this application?

system.diagnostics.process will not open Excel file without Excel open first

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.

Error 80040154 Class not registered - how to fix for ARX SAPILib.dll

I've been using CoSign within Microsoft Word successfully, but now I'm trying to automate the report generation using Microsoft Visual Basic Studio 10 Express. Trying to download the developer's software bundle fails due to the previous client installation, but I do already see the Arx Signature API 6.20 installed on my desktop, and I can add a reference to the Interop.SAPILib.dll without a problem, through the COM tab; Intellisense recognizes all the appropriate functions, so everything seemed to be installed. However, when I build and debug the program, I am given the error 80040154 Class not registered, specifically on the first "Dim myFileHandle as New SAPILibrary.FileHandle" call. Previous calls work without error; they include creating MySAPI as a New SAPICrypt, MyHandle as a new SESHandle object, MyFieldHandle as new SAPILib.SigFieldSettings, and calls to MySAPI.init, MySAPI.HandleAquire, MySAPI.Logon. My code is below.
Other forum posts for this error cite the need for assuring x86 builds if using a 32-bit dll. I have confirmed that it is my solution's compile platform; I am using a 64-bit Toshiba running Windows 7.
Can it be a dll issue, since the other SAPILibrary class reference worked well?
Does the Arx Cosign installation not automatically register the dll, despite my being able to reference it in Visual Stuio Express? I tried to manually register the dll file, but I'm then given the error that the module was loaded but that the entry point DllRegisterServer was not found, and to check to see if this is a valid dll.
Obviously I'm new to COM dlls. Am I on the right track, or is this an unhandled error of another kind?
Private Sub SignWithSAPI()
Dim username As String = "XXX#yahoo.com"
Dim password As String = "passwordhere"
'add a signature field locator string - NEED TO HIDE THIS AS IT DOESN'T GET ERASED BY SAPI
Dim MyFieldLocatorString As String = "<<<W=200;H=120;N=Physician signature;A=&HC;>>>"
oWord.Selection.TypeText(MyFieldLocatorString)
'SIGN PDF HERE USING COSIGN Signature API
Dim mySAPI As New SAPICrypt
Dim myHandle As New SESHandle
Dim rc As Int32
rc = mySAPI.Init()
If rc <> 0 Then
MessageBox.Show("Init failed")
Exit Sub
End If
rc = mySAPI.HandleAcquire(myHandle)
If rc <> 0 Then
MessageBox.Show("failed at handleAcquire")
mySAPI.Finalize()
Exit Sub
End If
rc = mySAPI.Logon(myHandle, userName, "", password)
If rc <> 0 Then
MessageBox.Show("Login failed")
mySAPI.HandleRelease(myHandle)
mySAPI.Finalize()
Exit Sub
End If
Dim MyFieldSettings As New SAPILib.SigFieldSettings
With MyFieldSettings
.Invisible = 0
.Height = 200
.Width = 100
.AppearanceMask = myChosenAppearancesMask 'shows graphical image, name of signer and time
.SignatureType = SAPI_ENUM_SIGNATURE_TYPE.SAPI_ENUM_SIGNATURE_DIGITAL
End With
Dim myPDFfileName As String = "C:\\Users\Scott\Desktop\TestAutomation.pdf"
Dim myFileHandle As New SAPILib.FileHandle
rc = mySAPI.CreateFileHandleByName(myFileHandle, _
SAPI_ENUM_FILE_TYPE.SAPI_ENUM_FILE_ADOBE, 0, myPDFfileName)
If rc <> 0 Then
MessageBox.Show("Error in creating FileHandlebyName")
mySAPI.HandleRelease(myHandle)
mySAPI.Finalize()
Exit Sub
End If
'Assigns the SigFieldContext
Dim mySigFieldContext As New SAPIContext
Dim myNumberOfSigFields As Integer
rc = mySAPI.SignatureFieldEnumInitEx(myHandle, mySigFieldContext, _
SAPI_ENUM_FILE_TYPE.SAPI_ENUM_FILE_ADOBE, "", myFileHandle, 0, myNumberOfSigFields)
If rc <> 0 Then
MessageBox.Show("Error in SigFieldEnumInitEx")
mySAPI.HandleRelease(myFileHandle)
mySAPI.HandleRelease(myHandle)
mySAPI.Finalize()
Exit Sub
End If
Dim mySigFieldLocatorContext As New SAPIContext 'next line assigns its value in the function
rc = mySAPI.SignatureFieldLocatorEnumInit(myHandle, mySigFieldLocatorContext, _
myFileHandle, "<<<", ">>>", 0, myNumberOfSigFields)
If rc <> 0 Then
mySAPI.ContextRelease(mySigFieldContext)
MessageBox.Show("Error in SigFieldLocatorContext")
mySAPI.HandleRelease(myFileHandle)
mySAPI.HandleRelease(myHandle)
mySAPI.Finalize()
Exit Sub
End If
Dim mySigFieldHandle As New SigFieldHandle
rc = mySAPI.SignatureFieldEnumCont(myHandle, mySigFieldContext, mySigFieldHandle)
'assigns the first(only) value to mySigFieldHandle
If rc <> 0 Then
mySAPI.ContextRelease(mySigFieldLocatorContext)
mySAPI.ContextRelease(mySigFieldContext)
MessageBox.Show("Error in SigFieldLocatorContext")
mySAPI.HandleRelease(myFileHandle)
mySAPI.HandleRelease(myHandle)
mySAPI.Finalize()
Exit Sub
End If
'//Create the Field
rc = mySAPI.SignatureFieldSignEx(myHandle, mySigFieldHandle, myChosenAppearancesMask, _
Nothing)
If rc <> 0 Then
MessageBox.Show("Error in sigfieldSignEx")
End If
'release resources
mySAPI.HandleRelease(mySigFieldHandle)
mySAPI.HandleRelease(myFileHandle)
mySAPI.ContextRelease(mySigFieldContext)
mySAPI.ContextRelease(mySigFieldLocatorContext)
mySAPI.Logoff(myHandle)
mySAPI.HandleRelease(myHandle)
End Sub
Thanks!
The FileHandle object can be created using either CreateFileHandleByName or CreateFileHandleByMem functions and this is the proper way to instantiate the object in our COM. Replacing the line Dim myFileHandle As New SAPILib.FileHandle with Dim myFileHandle As SAPILib.FileHandle = Nothing will solve your issue.