.Net/Mono & Ubuntu versus log4net - mono

I've been asked to write a small instrument-calibration app on Ubuntu Linux (14.04) and have been writing some small proof-of-concept apps (serial i/o, GUI, SQLite, etc.) to see if Mono is a good fit. Things were going well until I tested log4net, my favorite logging package. I cannot get the code to work. Here's a simple test app that works fine on a Windows box:
using System;
using log4net;
using log4net.Config;
public class L
{
public static void Main(string[] args)
{
Console.WriteLine("Version: " + Environment.Version);
XmlConfigurator.Configure(
new System.IO.FileInfo("console.logconfig.xml"));
Console.WriteLine("logging configured.");
ILog log = LogManager.GetLogger("root");
log.Info("This is an info message.");
log.Warn("This is a warning message.");
log.Error("This is an error message.");
}
}
Compiled with
gmcs -pkg:log4net,dotnet -main:L -out:L.exe L.cs
the code compiles, but generates a runtime error:
Version: 2.0.50727.1433
Missing method System.Reflection.Assembly::op_Equality(Assembly,Assembly) in assembly /usr/lib/mono/2.0/mscorlib.dll, referenced in assembly /usr/lib/mono/gac/log4net/1.2.10.0__a5715cc6d5c3540b/log4net.dll
Unhandled Exception:
System.MissingMethodException: Method not found: 'System.Reflection.Assembly.op_Equality'.
at log4net.LogManager.GetRepository (System.Reflection.Assembly repositoryAssembly) [0x00000] in <filename unknown>:0
at log4net.Config.XmlConfigurator.Configure (System.IO.FileInfo configFile) [0x00000] in <filename unknown>:0
at L.Main (System.String[] args) [0x00000] in <filename unknown>:0
This looks like a .Net version mismatch (maybe op_equality wasn't available in .Net 2.0?). When I try to force version 4 or 4.5 of the SDK:
gmcs -sdk:4.5 -pkg:log4n35,dotnet -main:L -out:L.exe L.cs
I get a compile error:
error CS0006: Metadata file `cscompmgd.dll' could not be found
This is on a brand-new Ubuntu 14.04 VM with Mono installed via:
sudo apt-get install mono-complete
sudo apt-get install liblog4net1.2-cil
sudo apt-get install liblog4net-cil-dev
Recommendations, please?

Unfortunately the version of log4net packaged for Ubuntu (1.2.10) is pretty old and known to have problems with .NET 4.0. 1.2.11 has been released in October 2011 and as of this writing 1.2.13 is the latest release.
You need to download the latest version from the Apache log4net site directly: http://logging.apache.org/log4net/download_log4net.cgi

You almost had it; Ubuntu 14.04:
gmcs -sdk:4.5 -r:/usr/lib/cli/log4net-1.2/log4net.dll App.cs

Related

"Could not load file or assembly or one of its dependencies" in Mono but not in native .NET

The same executable that uses some proprietary DLLs, after being compiled with Mono, works natively on Windows, but doesn't work using Mono on Windows or Linux.
hello_onbase.cs:
using Hyland.Unity;
using Hyland.Types;
using System;
public class HelloOnBase
{
public static void Main(string[] args)
{
var auth = Application.CreateOnBaseAuthenticationProperties("app_server_url", "user", "password", "data_source");
var app = Application.Connect(auth);
Console.WriteLine ("OnBase connection successful!");
}
}
Proprietary DLLs Hyland.Unity.dll and Hyland.Types.dll are in the same directory as the file hello_onbase.cs. Unfortunately I can't share those files since they're the IP of our vendor, I'm very sorry...
I opened Mono x64 Command Prompt in Windows and compiled the file successfully with Mono:
C:\Users\apanasenco\git\docaccess\services\doc\onbase>csc -r:Hyland.Types.dll -r:Hyland.Unity.dll hello_onbase.cs
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.
The executable Mono compiled executes just fine natively in Windows:
C:\Users\apanasenco\git\docaccess\services\doc\onbase>hello_onbase.exe
OnBase connection successful!
However, running the executable with mono causes the following error:
C:\Users\apanasenco\git\docaccess\services\doc\onbase>mono hello_onbase.exe
Unhandled Exception:
System.TypeLoadException: Could not set up parent class, due to: Could not set up parent class, due to: Could not load type of field 'Hyland.Types.EncryptedServiceObject:_scp' (2) due to: Could not load file or assembly 'Hyland.Security.Legacy, Version=0.2.2.0, Culture=neutral, PublicKeyToken=e169a6a902bdd7a6' or one of its dependencies. assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:EncryptedServiceObject member:(null) assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:ParameterizedObject member:(null)
at Hyland.Unity.OnBaseAuthenticationProperties.ConnectNormalMode (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00000] in <80532c8c2f134d0daba2ee8243cb5721>:0
at Hyland.Unity.OnBaseAuthenticationProperties.ConnectAndGetIntegrationApplicationOptions (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
at Hyland.Unity.Application.Connect (Hyland.Unity.AuthenticationProperties connectProperties) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
at HelloOnBase.Main (System.String[] args) [0x0001b] in <73b1617068fa44e792f55cccc5974b17>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not set up parent class, due to: Could not set up parent class, due to: Could not load type of field 'Hyland.Types.EncryptedServiceObject:_scp' (2) due to: Could not load file or assembly 'Hyland.Security.Legacy, Version=0.2.2.0, Culture=neutral, PublicKeyToken=e169a6a902bdd7a6' or one of its dependencies. assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:EncryptedServiceObject member:(null) assembly:C:\Users\apanasenco\git\docaccess\services\doc\onbase\Hyland.Types.dll type:ParameterizedObject member:(null)
at Hyland.Unity.OnBaseAuthenticationProperties.ConnectNormalMode (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00000] in <80532c8c2f134d0daba2ee8243cb5721>:0
at Hyland.Unity.OnBaseAuthenticationProperties.ConnectAndGetIntegrationApplicationOptions (Hyland.Unity.Services.IConnectServiceAccess connectServiceAccess) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
at Hyland.Unity.Application.Connect (Hyland.Unity.AuthenticationProperties connectProperties) [0x00020] in <80532c8c2f134d0daba2ee8243cb5721>:0
at HelloOnBase.Main (System.String[] args) [0x0001b] in <73b1617068fa44e792f55cccc5974b17>:0
Mono version on Windows and Linux: 6.12.0
The older versions of these two files used to work on Mono before... I'm wondering if there's some Mono setting I can tweak to relax some assembly checks to match native .NET behavior?
Turns out the vendor does provide a file Hyland.Security.Legacy.dll that was alluded to in the error message. Including that file resolved the issue.

ASP.NET vNext on Linux Ubuntu 14.04. Unable to load Kestrel

I've installed mono 3.8.0, installed kvm and ran the kp=vm upgrade and
My K runtime version is as follows
Active Version Runtime Location Alias
1.0.0-beta3 mono ~/.k/runtimes default
After running the kpm restore from the folder containing the project.json file
I get an error while running the k kestrel command.
I guess the following error has to do with the libuv installation, which I also have installed - version 1.4.2, or at least I think so. Has anyone come across this error ?
System.InvalidOperationException: Unable to load application or execute command 'Microsoft.AspNet.Hosting'. Available commands: web, kestrel. at Microsoft.Framework.ApplicationHost.Program.ThrowEntryPointNotfoundException (Microsoft.Framework.Runtime.DefaultHost host, System.String applicationName, System.Exception innerException) [0x00000] in <filename unknown>:0 at Microsoft.Framework.ApplicationHost.Program.ExecuteMain (Microsoft.Framework.Runtime.DefaultHost host, System.String applicationName, System.String[] args) [0x00000] in <filename unknown>:0 at Microsoft.Framework.ApplicationHost.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Turns out that the problem was pretty simple. Although I had the kestrel command defined in the project.json file, I did not include the "Kestrel" dependency in the dependencies section.
Once I added that it worked.
For beta3, you need mono 3.12..

Nginx, mono-fastcgi, ServiceStack install

The ServiceStack website has build / install instructions for windows (Nuget). There are many posts referring to mono based ServiceStack, but never any instructions for how to build on Centos for example. I downloaded and built ServiceStack on windows and tried to bring the files over to Centos. So far this has not worked for my integration with mono-fastcgi. I get errors in the browser: "Parser Error Message: Cannot find type ServiceStack.Examples.Host.Web.Global" for example. This particular error is not really my question, unless it can get me further towards a ServiceStack installation that works. The real question is what is the best way to install ServiceStack and build it on Centos? (And getting Nuget to work on Centos is not a solution.. at least I can't get Nuget to build).
After working the steps listed below in discussion with Scott, the nuget.exe command line package manager gets the following errors:
[root#buffer1 nuget]# /usr/local/bin/mono nuget.exe install ServiceStack -Verbosity detailed -ConfigFile /root/nuget/NuGet.config
WARNING: Invalid certificate received from server. Error code: 0xffffffff800b010a
System.InvalidOperationException: Unable to find package 'ServiceStack'.
at NuGet.PackageRepositoryHelper.ResolvePackage (IPackageRepository sourceRepository, IPackageRepository localRepository, IPackageConstraintProvider constraintProvider, System.String packageId, NuGet.SemanticVersion version, Boolean allowPrereleaseVersions) [0x00000] in <filename unknown>:0
at NuGet.PackageRepositoryHelper.ResolvePackage (IPackageRepository sourceRepository, IPackageRepository localRepository, System.String packageId, NuGet.SemanticVersion version, Boolean allowPrereleaseVersions) [0x00000] in <filename unknown>:0
at NuGet.PackageManager.InstallPackage (System.String packageId, NuGet.SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions) [0x00000] in <filename unknown>:0
at NuGet.Commands.InstallCommand.InstallPackage (IFileSystem fileSystem, System.String packageId, NuGet.SemanticVersion version) [0x00000] in <filename unknown>:0
at NuGet.Commands.InstallCommand.ExecuteCommand () [0x00000] in <filename unknown>:0
at NuGet.Commands.Command.Execute () [0x00000] in <filename unknown>:0
at NuGet.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[root#buffer1 nuget]#
Any ideas on using the command line nuget?
You mentioned that you have managed to get Mono to build on CentOS.
Don't build ServiceStack from source:
While it is possible, it's unnecessary. You can copy the existing ServiceStack dlls you may have from Windows; you don't need a special build, nor do you have to build them yourself on CentOS.
No Build instructions ... use NuGet:
There aren't specific instructions for building ServiceStack on CentOS, because there aren't instructions for building it from source at all. The recommended approach is to obtain the ServiceStack dlls from NuGet. But you'll only want to do that if you are using the CentOS machine as your development machine. In which case you can download the NuGet command line tool. Then simply run:
mono nuget.exe install ServiceStack
Then in you development IDE (I recommend monodevelop) reference the files that were downloaded by NuGet. See here for instructions on how to get Mono and MonoDevelop running on CentOS.
Invalid Certificate Warning:
This occurs when you haven't added the Mozilla Trusted Root Certificate Providers to the mono trusted providers store. You just need to do this action once, and mono will start trusting SSL certificates from the standard trusted sources:
mozroots --import --sync
See here for more information about Mono SSL Security.
Deploying:
It's just a case of copying your published project to CentOS and following these configuration instructions from the documentation. Except instead of using apt-get to install nginx you will need to use yum. But the configuration of nginx and fastcgi is the same.

Does fastcgi-mono-serverX work with mono 3.0 & nginx 1.2.4

I have been trying for some days to get mono 3.0 & nginx 1.2.4 and fastcgi-mono-serverX in the XSP 2.10 package going on Centos 6.3 ...the XSP4 server works but I can't get the fastcgi method working.
I built and tested mono 3.0 from source, it works fine.
I followed the config at http://www.mono-project.com/FastCGI_Nginx to no avail and many other settings from the nginx site.
...does the current XSP 2.10 module work with mono 3.0?
...should I downgrade mono to 2.11.4 to work with XSP 2.10?
...ultimately I would like to run ASP.Net 4.0 Web Forms
Update: Here's some output from the mono-server.log:
Server stack trace:
at Mono.WebServer.FastCgi.ApplicationHost.ProcessRequest (Mono.WebServer.FastCgi.Responder responder) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
at (wrapper xdomain-dispatch) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (object,byte[]&,byte[]&)
Exception rethrown at [0]:
---> System.InvalidCastException: Cannot cast from source type to destination type.
at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <filename unknown>:0
at Mono.WebServer.FastCgi.WorkerRequest..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at (wrapper xdomain-invoke) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
at (wrapper remoting-invoke-with-check) Mono.WebServer.FastCgi.ApplicationHost:ProcessRequest (Mono.WebServer.FastCgi.Responder)
at Mono.WebServer.FastCgi.Responder.Process () [0x00000] in <filename unknown>:0
[2012-11-05 12:35:14Z] Error Failed to process connection. Reason: The object was used after being disposed.
I was about to file a bug report with Xamarin... then I came across this submitted bug report from a year ago.
https://bugzilla.xamarin.com/show_bug.cgi?id=2876
tl;dr
You need to update the shell script (found with which mono-fastcgi-server4), and move mono-fastcgi-server4.exe from /usr/lib/mono/4.0 to /usr/lib/mono/4.5.
Longer Explanation
As mentioned, I'm using the mono-fastcgi-server4 package directly from the main canonical Ubuntu source which lists these file contents
/usr/bin/fastcgi-mono-server4
/usr/lib/mono/4.0/fastcgi-mono-server4.exe
/usr/lib/mono/gac/fastcgi-mono-server4/2.10.0.0__0738eb9f132ed756/fastcgi-mono-server4.exe
/usr/share/doc/mono-fastcgi-server4/AUTHORS
/usr/share/doc/mono-fastcgi-server4/NEWS.gz
/usr/share/doc/mono-fastcgi-server4/README
/usr/share/doc/mono-fastcgi-server4/README.Debian
/usr/share/doc/mono-fastcgi-server4/changelog.Debian.gz
/usr/share/doc/mono-fastcgi-server4/copyright
/usr/share/man/man1/fastcgi-mono-server4.1.gz
Based on the bug report solution, I was able to get this working. Essentially you edit the shell script used to launch fastcgi-mono-server4.exe by hand (which should be in /usr/bin), and move the .exe file by hand... or... you can use this little snippet of script that I incorporated into the deploy:setup of a Capistrano script. It uses sed to update the script.
fastcgi=$(which fastcgi-mono-server4) &&
sudo sed -i.bak -e 's/4\\.0/4.5/' $fastcgi &&
fastcgi_src='/usr/lib/mono/4.0/fastcgi-mono-server4.exe' &&
fastcgi_dest='/usr/lib/mono/4.5/fastcgi-mono-server4.exe' &&
if [ -f "$fastcgi_src" ]; then sudo mv $fastcgi_src $fastcgi_dest; fi;
This report also seems related
https://bugzilla.xamarin.com/show_bug.cgi?id=3582
If you use Mono 3.0, use a tag from xsp that is 3.x too. End of story.
Also, to avoid bugs like 3582, use Mono 3.0.3 or higher.

Not able to open MonoDevelop v 2.4.2

When I try to open MonoDevelop this error appears in the console log
com.apple.launchd.peruser.501[249] ([0x0-0x13013].com.ximian.monodevelop[308]) Exited with exit code: 255
How can I fix the problem?
EDIT: Snow Leopard 10.6.8, MonoDevelop 2.4.2 and Mono 2.10.5.
UPDATE: This is the error if I try to run MonoDevelop from shell
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/MonoDevelop.app.
UPDATE 2: I've found the crash reporter for mono
FATAL ERROR [2011-09-03 15:06:25Z]: MonoDevelop failed to start. Some of the assemblies required to run MonoDevelop (for example gtk-sharp, gnome-sharp or gtkhtml-sharp) may not be properly installed in the GAC.
System.DllNotFoundException: /Library/Frameworks/Mono.framework/Versions/2.10.5/lib/libgtk-quartz-2.0.0.dylib
at (wrapper managed-to-native) Gtk.Application:gtk_init (int&,intptr&)
at Gtk.Application.do_init (System.String progname, System.String[]& args, Boolean check) [0x00000] in <filename unknown>:0
at Gtk.Application.Init (System.String progname, System.String[]& args) [0x00000] in <filename unknown>:0
at MonoDevelop.Ide.IdeStartup.Run (System.String[] args) [0x00000] in <filename unknown>:0
at MonoDevelop.Startup.MonoDevelopMain.Main (System.String[] args) [0x00000] in <filename unknown>:0
Any help?
For those interested in:
Uninstall Mono with this script uninstall script. You have to save the script in a file with extension .sh
Save the file in the desktop as uninstallMonoFr.sh (for example)
Open a terminal window: cd Desktop, sudo ./uninstallMonoFr.sh, insert your pwd
Download mono framework 2.10.4 (this version works for me)
Install again
I don't know if the problem is due to 2.10.5 version of mono framework. 2.10.4 works well.
UPDATE Seems that Mono 2.10.5 still presenting a package bug. MonoDevelop can't open with this version. Mono 2.10.4 works.
UPDATE 2 I've just installed 2.10.6 and it works. MonoDevelop now opens correctly.
This also helped me (permission issue):
http://answers.unity3d.com/questions/277759/cannot-start-built-in-monodevelop.html
I just added myself (user) with read&write permissions.