Getting ServiceStack example to work - c#

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.

Related

System.PlatformNotSupportedException when referencing System.Data.SqlClient ONLY when running as a docker image

I'm trying to run my azure function application as a docker image and when I do it throws me a System.PlatformNotSupportedException in Microsoft.Data.SqlClient.dll: 'Strings.PlatformNotSupported_DataSqlClient' exception any time I try to call my datalayer (no matter if its EF Core or Dapper that I use). I can run the application just fine when setting my API project as startup instead of the docker image.
There are very similar questions out there but none of them take into account that it is ONLY happening when I try to run it as a docker image or the fact that my target framework is netcoreapp3.1. I've already tried what the similar questions said. which is to add System.Data.SqlClient as a Nuget package which doesn't help no matter what version I make it.
I suspect I need to add something to the Dockerfile or something.
here is some additional information:
EDIT:
I am able to recreate the issue in a new project by simply creating an azure function, adding docker support, creating a simple data layer that performs a CRUD operation on a local database, then running the docker image and calling the endpoint that does the CRUD operation. Hope that helps.
The Microsoft.Data.SqlClient NuGet package includes a number of DLLs supporting different .NET targets and different runtime platforms. If you are getting a
PlatformNotSupported Exception
it ultimately means your application is not loading the appropriate DLL.
A different DLL for .NET Framework, .NET Core, .NET Standard, Windows, Linux, etc. The NuGet infrastructure will automatically reference and load the appropriate DLL based on your application's needs.
If your application loads a DLL from a NuGet package directly, it bypasses all this logic and probably loads the incorrect DLL.
The DLL in the NuGet package under lib/netstandard2.0/Microsoft.Data.SqlClient.dll is basically the fallback DLL for any unsupported target and simply throws the PlatformNotSupported exception for any call. This is a nicer exception than what you would otherwise get when running on a platform that does not have a DLL built for it. Ultimately, you want to use the NuGet package reference infrastructure or you would have to implement all this target framework and platform support logic yourself when determining which DLL to load.
Additionally, the NuGet package contains all the dependency information for the SqlClient library and facilitates the downloading and referencing of dependencies. If you reference and load an individual DLL manually, it is up to you to ensure all dependencies are also available to the SqlClient library.
Refer why do i get a platformnotsupported exception when my application hits a sqlclient method
You can update all your dependencies with latest versions. It may fix your problem. Please check the implemented target frameworks and platforms support the logic of your code.
Refer here Link 1 & Link 2

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.

ILNumerics mkl_custom dll not found

We have two applications that use ILNumerics and have run into the same issue with both. We use the mkl_custom.dll and during development the application runs fine. The dll in use during development sits in the bin32 folder automatically generated when downloading the ILNumerics from nuget. However when we install the applications we get "Unable to load DLL 'mkl_custom': The specified module could not be found. (Exception from HResult: 0x8007007E".
Here is what we have tried:
Building the application in Any CPU, x86.
Switching the bin32 to include the bin64 dll's and viсе-versa.
Running dependency walker and including all dll's that are needed.
Changing path variable.
We are using ILNumerics 3.3.3.0.
One of the dependencies for mkl_custom is msvcr*.dll. Packing this dll manually may work on some operating systems but not all. Make sure the target system has c++ runtime redistributable package installed.
This installs the msvcr dll correctly. Hopefully this should fix the issue

merge dependent dlls in c# application

I have created a backup console application (this is 32bit program running on .net 3.5 on windows 8 64bit) with these dlls:
Delimon.Win32.IO,
SevenZipSharp,
7z(native) dll
I have tried to merge them with ilmerge but program still asks dlls( Delimon.Win32.IO not found ) while startup.
Then I tried second solution:
add dll's to resources & handle AssemblyResolve event, still same problem.
Any clue what is problem?.
I dont want any commercial solution.
I'd recommend using Costura.
https://github.com/Fody/Costura
Costura is avaliable on NuGet and is a simple solution for providing a custom AssemblyResolve system. It will take all your projects references and automatically add them at build time.
Also, if you have native or mixed-mode assemblies (like for example 7zip) then you'll need to provide Costura with a bit of configuration. Everything is covered in the readme.

How to merge the dependant dll (MySql.Data.dll) with my created exe?

I have created an application which requires the ODBC Connector to be installed on the computer to work. As my application need to connect to mysql database, it needs only one dll file (MySql.Data.dll) to work.
When i put this dll in the same location as the application it works ok. Now i want to merge this dll so that i will have only one Executable at the end ?
How can i merge this dependant DLL with my executable ?
You can't do that, all assemblies will get referenced from somewhere...
From the .NET framework path like:
System.Net.dll
All .NET apps need .NET Framework assemblies to run and that's why the user that want to execute your app needs .NET Framework installed. So your app knows where to find this assembly and won't need you to put, for example, the System.Net.dll assembly in the same path of your app for a success running.
Or from external paths like you app does.
Your app knows where to find .NET Framework assemblies to run but wait! it needs also some extra dll to run, so that's why you get the MySql.Data.dll in the same path when compiling your app.
Possible solution:
1. If you want to make just one executable try to use Spoon Studio (hard to find full cracked version and expensive to buy it). This will give you the possibility to embedded any assembly like the one you want or all .NET Framework, so this will make your app not dependant from any .NET Framework installation or needed assembly in the user computer that executes your app.
2. Try to use ILMerge, but please read below links to know if your code fits the requirements.
How to and important information:
http://www.codeproject.com/Articles/9364/Merging-NET-assemblies-using-ILMerge
http://www.blackwasp.co.uk/ILMerge.aspx
If it's a pure .NET module, you can try the ilmerge utility.

Categories