Can't load dll when send application to another PC - c#

I have the following solution:
MySolution
-Project: MyServer (WPF)
-Project: MyClient (WPF)
-Project: MyLibrary (Class library)
Inside MyLibrary, I reference an external DLL System.Data.SQLite for SQLite access. I set the dll to Copy to local so that when I build, it will copy the dll into the directory where the class library MyLibrary will be built into a dll.
In the other two projects (MyClient and MyServer) I reference the class library project so I can have access to my shared routines but also have access to the SQLite libraries. This works great on the dev machine, but when I copy the Release folder to another machine, the Client/server apps refuse to run throwing an error that it can't find the SQLite dll.
What am I doing wrong here ?
Regards

Check that you have a sqlite.dll in your release folder. You can install i using nuget with the Package Management Console command "Install-Package System.Data.Sqlite".
If you then get a "BadImageFormat" exception, make sure you are using the correct version of sqlite for your system. It comes in 32 and 64-bit flavors.

Related

Do .dll 's retain any references added to your project?

PROBLEM
I created a C# project that implements the System.Management.Automation reference (allowing me to write powershell commands in my project).
I compiled the project and copied the dll to the plugins folder of my Rainmeter application so that I could leverage it along with the other dll 's Rainmeter comes with.
This works perfectly on my machine (64 bit); however, I want to load this same configuration on another server (also 64 bit). Both machines are using the same installation of the .NET framework (4.5).
According to this source, I should be able to simply copy the Rainmeter folder with the included dll and it should run without any problems (I'm using the portable installation of Rainmeter).
I receive the error "System.IO.FileNotFoundException" unless I remove the "SystemVersion.dll" that I created, when running Rainmeter on another server.
QUESTION
Since the issue is clearly the dll I have added, I'm assuming the reference is not being added to the dll?
=========================================================================
EDIT
As per #Hackerman 's answer, the issue was that the dll was unable to find my reference. The path for System.Management.Automation required powershell version 3.0 to be installed on the machine in order to load the reference.
My server was running powershell version 2.0, but after installing version 3.0 the dll was able to load the reference and Rainmeter would display my results as expected.
When you build your class library, the references don't get embedded on your final dll. The System.IO.FileNotFoundException that you are getting is because your dll can't load the System.Managem‌​ent.Automation.dll reference on the destination server. Installing PowerShell 3.0 on the server should resolve the issue.

How can i install Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll in GAC

I've made a project with c# in which I use "Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll" as a reference assembly.
When I install my program on another computer it gives me an error message:
unable to run the application requires that assembly
microsoft.data.schema.sql.unittesting version 12.0.0.0 in the global
assembly cache
How can I install this .dll in GAC using code.
This assembly is used for unit testing databases. It's shouldn't be needed by your production code.
Remove it from your project references and try if the solution still builds and, if so, the program still works on both your machine as well as on another machine.

c# Sqlite 1.0.84.0 vs 1.0.89.0

I've an app in c# and it's working perfect with Sqlite 1.0.84.0 but I should update it to 1.0.89.0.
I replace the dll and some functionalities are not working any more. Im pretty sure that is something related with SQLite.Interop.dll but I don't know how to solve it. Any idea?
Thank you in advanced for the anwer.
I suspect there is a mixup on which dll goes where and how it gets copied to the working directory.
Instead of adding references to SQLite manually, you should add it and update it using its nuget package. The package adds the proper SQLite.dll and Interop.dll files for the current SQLite version and bitness (x86 or x64) and ensures the proper Interop dlls are copied to the debug directory (x86 or x64).
SQLite is a native library so you need to have the proper version for the OS you are targetting. System.Data.SQLite is a library built on top of the native dll, which communicates whith it using the Interop dll.

Getting ServiceStack example to work

I am new to ServiceStack. I am testing out the MovieREST example. When I run the project, the Immediate Window shows me this error
"A first chance exception of type 'System.DllNotFoundException' occurred in Mono.Data.Sqlite.DLL"
and no movie list is loading up. So, there is only a blank "Add a new movie" page with some default inputs, everytime I hit Add new movie, the DllNotFoundException will be thrown.
Do I need to install any dependency projects to make it work? I am running it with VS2010, IIS, and Vista 32bit (yup..I know..). Also installed Mono and sqlite 32bit just now blindly, I am not even sure if the project needs them to run. From the code, I can see it is referring to "App_Data/db.sqlite" and References already has sqlite3.dll, I replaced the dll with the 32bit one I download anyway, but still no luck.
Please give me some hints on what I am missing? Thank you.
The Mono.Data.Sqlite.DLL is just a managed wrapper that needs to find the unmanaged sqlite3.dll in order to run (which is what holds the native binary of Sqlite itself).
It looks for this in the /bin directory, to have it deployed there whenever you build you need to copy sqlite3.dll to your project root / and set the Build Action to Content and change the Copy action to Copy if newer.
Ideally you'd want to use the right sqlite3.dll for your architecture (the ServiceStack.OrmLite.Sqlite.Mono NuGet package contains both 32bit / 64bit dlls) although IIS/.NET can work with 32bit unmanaged dlls but will require some tweaking explained here.
Using mixed-mode assemblies
Whilst Mono.Data.Sqlite.DLL lets you run the same .NET app on Mono, if you only want to run Sqlite in Windows you can also use the mixed-mode assemblies that have the unmanaged native sqlite library embedded in the .NET dll. There are 2 different versions available on NuGet:
ServiceStack.OrmLite.Sqlite32
ServiceStack.OrmLite.Sqlite64
Remove any references to existing OrmLite or Sqlite dlls as both of these NuGet packages contain all the Sqlite + OrmLite dlls needed.

Changes made to the dll are not reflecting in the Application where I am using this dll

I have a Class library project. I am installing this dll produced by the project into the GAC by the command "gacutil /i [Path of the dll]". This dll is used by a windows application. When windows application runs, it successfully accesses the functions and properties of the dll.
Now I have made some changes to the dll. I have uninstalled the original dll from the GAC and will install the newer dll with the required changes. Now when the windows application uses this dll, the new changes from the dll are not getting reflected in the application. The new changes should reflect into the application as I installed the new dll into the GAC.
The Name, version and Public key token is the same for both dlls. I think it won't matter as the i have uninstalled the previous dll and installed the new dll into the GAC.
Am I doing something wrong?? Please suggest a solution.
Thanks and Regards,
Mayur Mahajan
I would suggest for debugging purposes that you version your dll, then print the version to your application to be sure its being updated. Include the System.Reflection namespace and the code would run look like the following:
Assembly assembly = Assembly.LoadFrom("unknown.dll");
label.Text = assembly.GetName().Version.ToString();

Categories