Embedding ServiceStack dll to Mono Executable - c#

I''m trying to get a program i wrote in C# to work w/ Mono.
The project is here -- https://github.com/micahasmith/cstatic
I have the build script to "mono make" it set up like so--
dmcs -r:../packages/ServiceStack.Text.3.9.48/lib/net35/ServiceStack.Text.dll \
-target:exe -out:cstatic.exe \
`find . -name "*.cs"`
That builds fine and makes the cstatic.exe. However, when i go to run it like so
mono cstatic.exe i get the following:
Missing method ToJson in assembly /Users/micahasmith/Downloads/cstatic/CStatic/CStatic/cstatic.exe, type ServiceStack.Text.StringExtensions
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceStack.Text, Version=3.9.45.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'ServiceStack.Text, Version=3.9.45.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'ServiceStack.Text, Version=3.9.45.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'ServiceStack.Text, Version=3.9.45.0, Culture=neutral, PublicKeyToken=null'
Any ideas?

I needed to have the servicestack dll in the same folder as the mono generated exe file.

Related

"Could not load file or assembly" problem with MySQL.Data in .NET core

I am using Visual Studio Code and trying to write a script for GTA 5 RAGEMP using C#, im fairly new to C# and it was all going good untill i tried to create MySQL connector using MySQL.Data from oracle.
On my try - catch i get this:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'
String SQLConnection = $"SERVER={sql.Host};PASSWORD={sql.Password};UID={sql.Username};DATABASE={sql.Database}";
conn = new MySqlConnection(SQLConnection);
try
{
conn.Open();
NAPI.Util.ConsoleOutput("MySQL connection is up!");
IsConnectionSetUp = true;
}
catch(Exception ex)
{
NAPI.Util.ConsoleOutput(ex.ToString());
}
I get this in server console output:
Could not load file or assembly 'System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
And this in VSC console output:
Exception thrown: 'System.IO.FileNotFoundException' in MySql.Data.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
An exception of type 'System.IO.FileNotFoundException' occurred in System.Private.CoreLib.dll but was not handled in user code
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
I copied everything from MySQL/Connector to my runtime folder, i tried using NuGet to download System.Drawing.Common and System.Security.Permissions, i tried adding .DLLs manually to project dependecies, nothing worked.
I'm guessing RAGEMP embeds some version of the .NET Runtime that doesn't include those assemblies by default.
Try using nuget.org/packages/MySqlConnector instead. It also supports connecting to MySQL from C# but has fewer dependencies.

Error CS0234 after changing the .NET framework version of my Xamarin GTK# app

Full error message:
error CS0234: The type or namespace name 'GTK' does not exist in the namespace 'Xamarin.Forms.Platform' (are you missing an assembly reference?)
This occurs in Program.cs on this line:
using Xamarin.Forms.Platform.GTK;
The reason I had to change the .NET framework version is because I was trying to run the app on Linux, and Mono for Linux doesn't seem to support .NET Framework v4.7.2, so I changed it to 4.6.1 (the minimum required for Xamarin).
The weird thing is, if I open the file in question, Visual Studio says there are no errors, but the error still pops up in the output window when I actually try to build the project...
edit: there are some warnings above the error in the output window, here is the first one:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3274: The primary reference "Xamarin.Forms.Platform.GTK, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.7" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1".
This looks like I need to update my nuget packages, so I reinstalled the two Xamarin packages (Xamarin.Forms and Xamarin.Forms.Platform.GTK), and... same warning! Why can't nuget get the version of the package that is compatible with the version of .NET that I'm using?
edit: the reason I tried to change the .NET framework version is because I get this error running the Xamarin app on Linux:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

System.IO.FileNotFoundException : Could not load file or assembly 'nunit.core, Version=2.6.4.14350, Culture=neutral,

System.IO.FileNotFoundException : Could not load file or assembly 'nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The
system cannot find the file specified.
I am running the Test cases from teamcity using shell script and i am getting this above error, when i run the same from test explorer and it is executing fine.

mono - Mono.Options.dll not found

I'm trying to run a small C# application which parses its command-line arguments using Mono.Options. I added the following line to my .csproj:
<Reference Include="Mono.Options" />
and it compiles fine. However, when trying to actually run the application, I get the following error:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Options, Version=0.2.3.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies.
File name: 'Mono.Options, Version=0.2.3.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Options, Version=0.2.3.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies.
File name: 'Mono.Options, Version=0.2.3.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
What am I doing wrong? locate Mono.Options shows the following:
/home/martin/.cache/MonoDevelop-5.0/DerivedData/Mono.Options.dll-f8111709
/home/martin/.cache/MonoDevelop-5.0/DerivedData/Mono.Options.dll-f8111709/0
/home/martin/.cache/MonoDevelop-5.0/DerivedData/Mono.Options.dll-f8111709/0/assembly.data
/home/martin/.cache/MonoDevelop-5.0/DerivedData/Mono.Options.dll-f8111709/0/assembly.tag
/home/martin/.cache/MonoDevelop-5.0/DerivedData/Mono.Options.dll-f8111709/0/data.xml
/usr/lib/mono/4.5-api/Mono.Options.dll
/usr/lib/mono/4.5.1-api/Mono.Options.dll
/usr/lib/mono/4.5.2-api/Mono.Options.dll
(I'm not using Visual Studio, monodevelop or any such IDEs, so please don't tell me to click some magic button or tick an option on a menu).

C# Error after installation. Could not load file or assembly 'Newtonsoft.Json

in C# windows forms, I am creating a chat client to connect nodejs server (Socekt.io). I am using SocketIoClientDotNet.dll in C#. While in visual studio debug mode, all is well. But when I install the app through creating the installer of the app, it is giving the following error when I call the socket.Emit('func',data) function.
Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
This is the line where exception is occurring:
socket.Emit("msg", "text", txtMessage.Text, receiverId, senderId);
Make sure the Newtonsoft.Json.dll file is included in the installer.
You could also try (re)installing the SocketIoClientDotNet using NuGet.
PM> Install-Package SocketIoClientDotNet

Categories