SQLite issues with finding SQLite.Interop.dll - sqlite

I'm using SQLite as a means of moving data between a UI and a service but I've run into a few problems. I've looked around and I can't see anyone else with an issue like this. I've triple checked all my references, the x64 folder containing the Interop dll is included in the project, all these dlls are set to copy to the output directory, all directories have the right permissions and nothing's worked.
This is part of a larger problem I'm experiencing where if I use an SQLite Connection in my BackgroundWorker Completed function then the entire service crashes out with File not found exception, if I run an SQLite Connection inside the actual BackgroundWorker I get the Unable to load DLL 'SQLite.Interop.dll' error and finally if I use an SQLite Connection in a function that has no relation to a BackgroundWorker then it works perfectly (referencing this function from either BackgroundWorker event functions results in the same errors respectively).
Any help on this would be great
Code
Dim LiteUpdateString As String = ""
Dim LiteConnection = New SQLiteConnection("Data Source=C:\...\AppData\Roaming\OPCService\Tags.db;Version=3;FailIfMissing=True")
Dim LiteUpdate As String = ""
UpdateNumber += 1
teststring += UpdateNumber.ToString
LiteUpdate = $"UPDATE SQLiteTags SET TagQuality='{teststring}' {SQLWhere}"
Dim Command As New SQLiteCommand(LiteUpdate, LiteConnection)
LiteConnection.Open()
Command.ExecuteReader()
LiteConnection.Close()
Errors
BackgroundWorkerCompleted
Application: OPCService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at OPCService.OPCService.BackgroundWorker1_RunWorkerCompleted(System.Object, System.ComponentModel.RunWorkerCompletedEventArgs)
at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
BackgroundWorker
Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I finally managed to find a somewhat workaround, since I can use SQLite in an independent function but can't call that function from a BackgroundWorker event thread, I start a timer once the thread is completed to execute the independent SQLite function.

Related

What could cause GDI+ Initialize exception

I spend a lot of time to search answer but I didn't found it. We have console application (exe) with C1 Report Component for automated printing task. This application is executed from cmd file and cmd file is called by cmdexec from SQL Server 2014 every minute. It's work very fine but there is exceptiton GDI+ Initialize - System.Drawing.SafeNativeMethods+Gdip.Initialize aproximetelly montly. There is no chance to solve this so we must restart server.
I tried to create cmd file with echo command. It was worked fine and I got output from echo. So I created application with Console.Writeline("Hello world") only. It was worked fine. Then I add reference to System.Drawing. Nothing happend - ouput was produced. Then I created System.Drawing.Bitmap object and I got GDI+ Initialize exception.
Job on SQL server run as SQLRUNSERVICES and it is in Administrator group. But when I log as SQLRUNSERVICES and launch our application in command line, application works fine without exception. When I log as another user there is no problem with this. Only with SQLRUNSERVICES throught SQL Proxy.
I suppose there must be something wrong with windows session. This application starts, prints some reports and finishes. So I suppose when application finishes memory will be free and GDI object will be free so. I check if we have call dispose method for each object working with GDI.
Can I have some chance to see GDI objects used by session? Or what could cause this exception? I cannot use task manager because when application is not running there is nothing to see.
Thank you for replies. It is very stresfull problem for us because it is going repeatedly every month after restart server.
We created testing application to print most quickly and we got this exception for one day. We call Dispose method for C1Report ofcourse. We will try to use using section. But it looks like C1 error. Test application printed about 65000 count of document and then crashed by GDI+ Initialization Exception. There is stack:
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.SafeNativeMethods.Gdip.Initialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at C1.C1Preview.GraphicsHolder.FromBitmap()
at C1.C1Preview.GraphicsHolder.FromScreen()
at C1.C1Preview.C1PrintDocument.SelectBestMeasurementDevice(Boolean showWarning, MeasurementDeviceEnum& measurementDevice, String& measurementPrinterName, GraphicsHolder& measurementGraphicsHolder)
at C1.C1Preview.C1PrintDocument.#fFe()
at C1.C1Preview.C1PrintDocument.SetCreationDevice(MeasurementDeviceEnum creationDevice, String creationPrinterName)
at C1.C1Report.Layout..ctor(C1Report report)
at C1.C1Report.C1Report.Initialize()
at C1.C1Report.C1Report..ctor()

Unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

I'm having trouble with this block of code. The StreamWriter creates the .txt document and puts it in the projects bin folder, but when I run the program, I get an error that says:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
the process cannot access the file ... because it is being used by another process.
There are no other programs running on my computer, so I'm not sure what other process could be using it. Here's my code, thanks in advance.
Private Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
Dim voteWriter As IO.StreamWriter
Dim vote As String
voteWriter = IO.File.AppendText("warrenHS.txt")
vote = Convert.ToString(canidateListBox.SelectedItem)
voteWriter.Write(vote)
End Sub
Make sure to close the stream after you are done with it.
voteWriter.Close()
Or you could use it in a using statement that will automatically close it at the end.

Problem Writing to Private Message Queue on Windows 7 64-Bit from .NET 2.0 Web Service

I have the following code in a web method of a .NET 2.0 VB web service application:
<WebMethod()> _
Public Function UpdateCall(<System.Xml.Serialization.XmlElement("CallChangeRequest")> ByVal callChange As CallChangeMessage) As Boolean
Dim result As Boolean = False
Dim mq As System.Messaging.MessageQueue = Nothing
Dim msg As System.Messaging.Message = Nothing
Try
mq = New System.Messaging.MessageQueue(System.Configuration.ConfigurationManager.AppSettings("queueName"))
mq.Formatter = New System.Messaging.XmlMessageFormatter(New Type() {GetType(CallChangeMessage)})
msg = New System.Messaging.Message(callChange)
msg.Recoverable = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings("recoverableMessages"))
mq.Send(msg)
result = True
Catch ex As Exception
Finally
If Not (msg Is Nothing) Then msg.Dispose()
If Not (mq Is Nothing) Then mq.Dispose()
End Try
Return result
End Function
This code correctly serializes my object and writes an XML message to the message queue on my old local development machine, which was running Windows XP Pro 32-bit. It also performs correctly on the production server. After upgrading to Windows 7 64-bit, this code will no longer write the XML message in the message queue. The call to msg.Send(msg) does not raise an exception, so my web method returns true to the caller. However, no message is written to the queue, so the code is just quietly failing.
The messages are marked as Recoverable, and the queue name is FormatName:DIRECT=OS:.\private$\inbounddata. I've opened up the permissions for basically everyone to do everything. If there were a permission problem, I would expect to get some sort of exception, so I don't think I have a permission problem. The web service is running in an application pool targeting the 2.0 framework with managed pipeline mode set to Classic.
Up to now, my recourse has been to deploy the code on my old development box, which I still have hanging around, but I cannot do that forever. Is there a problem with my code that is causing this to fail? Does anyone know of any issues with writing to MSMQ on Windows 7 64-bit from a 32-bit .NET 2.0 framework app?
Thanks for any help!
Don't know what happened, but I deleted the existing queue, created a new queue, and now all is well. Thanks for the suggestions.

HttpContext.Current.Session is throwing exception(Object reference not set to an instance of an object.) in business class

In our application we have to access session objects in business class. We are using HttpContext.Current.Session to get the session value. In some cases it returns the value but mostly its throwing a null reference exception(Object reference not set to an instance of an object). We have the following code
Try
If HttpContext.Current.Session("Username") IsNot Nothing then
' Statements to be executed
End If
Catch ex As Exception
'Log to db
End Try
Here HttpContext.Current.Session("Username") is mostly throwing an exception "Object reference not set to an instance of an object"
While debugging we found that HttpContext.Current itself is nothing.
Thanks. Any help on this will be appreciated.
If the production machine is IIS, there is an installation of "WebSocket protocol".
If the production machine is nginx, you need to set "proxy_set_header Connection" Upgrade ";".

ASP.Net String Assignment Failure

This is my first post here, so go easy on me :) I'm having an odd problem with an ASP.Net page. I'm getting an object not set error message when assigning a string literal to a variable. Here's the error I'm getting.
[NullReferenceException: Object
reference not set to an instance of an
object.]
Project.Page.Page_Load(Object sender,
EventArgs e) in
C:\Project\Page.aspx.vb:10
System.Web.UI.Control.OnLoad(EventArgs
e) +91
System.Web.UI.Control.LoadRecursive()
+74 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +2207
And here is the code that the error is pointing to. The last line in this fragment is the line 10 the error is complaining about
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim teststring As String
teststring = "test"
It seems it fails on accessing any reference type, even if it is declared locally in the load function. I originally found the problem when Request.IsSecureConnection was nulling out on me. I eventually discovered I could replace it with the above code and fail in the same way.
The problem does not always happen. It seems to be triggered by publishing an update from Visual Studio, or when I head home for the day and the server sits idle all night. One or two app pool recycles seems to clear it up, and the page functions correctly.
Any help would be greatly appreciated. I've been doing desktop development for a few years, but I'm fairly new to web development. So maybe this is something obvious I've got configured wrong. I'm currently using .Net 4 on IIS 6.
UPDATE
I was able to identify the line using the recommendation of copying the page, commenting everything out, and then uncommenting one line at a time. The line my test page started giving the error was this one
Dim StateName As String = State.Attribute(XName.Get("name")).Value
That code is in a foreach over an IEnumerable(of XElement). The stack trace still points to the string assignment, but all other stack traces are spot on, so I don't think it's a bad pdb.
Also, when the error occurred this time, no amount of recycling the app pool or stopping and starting it would fix the error. I finally got it working again by switching the application to a different app pool.
I don't see how that code could throw a null reference exception, are you sure it is not some other code, but the exception message is pointing to the wrong place becuase your pdb files are out of date. The most likely candidate for the code at fault based on your description is some code accessing an application variable that has become null becuase the app pool has recycled due to timeout or because you have republished the web app.
Try declaring the string as a constant... just to zoom in on the issue
Dim Const TESTSTR as String = "test"
Dim teststring As String
teststring = TESTSTR
If that doesn't work, move the Const declaration somewhere global. Maybe it's something to do with how/where .NET stores the string itself becoming invalid.
Try manually recycling the page every time you publish... maybe it's an issue of the pre-compiled code lingering after an update? I admit, that's a head-scratcher, a line like that should never fail.

Resources