Unhandled Exception: System.ComponentModel.LicenseException on mono/osx

Using the same wizard template C# DA server, replacing the Main program to this, so I can test it more easily (and because this http://connect.remobjects.com/discussion/710/c-mono-server-on-osx-do-nothing)

using System;

namespace BestSeller
{
	class ServerAdmin {
		private Engine fEngine;

		public void StartServer()
        {
            if (this.IsServerActive)
            {
                this.StopServer();
            }
            this.fEngine = new Engine();
            this.fEngine.Start();
        }

        public void StopServer()
        {
            if (this.IsServerActive)
            {
                this.fEngine.Dispose();
                this.fEngine = null;
            }
        }

        // Properties
        public bool IsServerActive
        {
            get
            {
                return ((this.fEngine != null) && this.fEngine.Active);
            }
        }	
	}
	
	class MainClass
	{	
		public static void Main (string[] args)
		{
			ServerAdmin server = new ServerAdmin();
			
			server.StartServer();
			
			Console.WriteLine ("Hello World!");
			Console.ReadKey();
			
			server.StopServer();
		}		
	}
}

I get this exception on run:

Unhandled Exception: System.ComponentModel.LicenseException: A system exception has occurred.
at RemObjects.DataAbstract.ROLicenseProvider.GetLicense (System.ComponentModel.LicenseContext context, System.Type aType, System.Object anInstance, Boolean aAllowExceptions) [0x00000] in :0
at System.ComponentModel.LicenseManager.privateGetLicense (System.Type type, System.Object instance, Boolean allowExceptions, System.ComponentModel.License& license) [0x00042] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System/System.ComponentModel/LicenseManager.cs:191
at System.ComponentModel.LicenseManager.Validate (System.Type type, System.Object instance) [0x00002] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System/System.ComponentModel/LicenseManager.cs:169
at RemObjects.DataAbstract.Server.ConnectionManager…ctor (IContainer aContainer) [0x00000] in :0
at (wrapper remoting-invoke-with-check) RemObjects.DataAbstract.Server.ConnectionManager:.ctor (System.ComponentModel.IContainer)
at BestSeller.Engine.InitializeComponent () [0x0000b] in /Users/mamcx/Downloads/BestSellerServer/Engine.Designer.cs:33
at BestSeller.Engine…ctor () [0x0000d] in /Users/mamcx/Downloads/BestSellerServer/Engine.cs:12
at (wrapper remoting-invoke-with-check) BestSeller.Engine:.ctor ()
at BestSeller.ServerAdmin.StartServer () [0x00011] in /Users/mamcx/Downloads/BestSellerServer/Program.cs:14
at BestSeller.MainClass.Main (System.String[] args) [0x00006] in /Users/mamcx/Downloads/BestSellerServer/Program.cs:43
[ERROR] FATAL UNHANDLED EXCEPTION: System.ComponentModel.LicenseException: A system exception has occurred.
at RemObjects.DataAbstract.ROLicenseProvider.GetLicense (System.ComponentModel.LicenseContext context, System.Type aType, System.Object anInstance, Boolean aAllowExceptions) [0x00000] in :0
at System.ComponentModel.LicenseManager.privateGetLicense (System.Type type, System.Object instance, Boolean allowExceptions, System.ComponentModel.License& license) [0x00042] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System/System.ComponentModel/LicenseManager.cs:191
at System.ComponentModel.LicenseManager.Validate (System.Type type, System.Object instance) [0x00002] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System/System.ComponentModel/LicenseManager.cs:169
at RemObjects.DataAbstract.Server.ConnectionManager…ctor (IContainer aContainer) [0x00000] in :0
at (wrapper remoting-invoke-with-check) RemObjects.DataAbstract.Server.ConnectionManager:.ctor (System.ComponentModel.IContainer)
at BestSeller.Engine.InitializeComponent () [0x0000b] in /Users/mamcx/Downloads/BestSellerServer/Engine.Designer.cs:33
at BestSeller.Engine…ctor () [0x0000d] in /Users/mamcx/Downloads/BestSellerServer/Engine.cs:12
at (wrapper remoting-invoke-with-check) BestSeller.Engine:.ctor ()
at BestSeller.ServerAdmin.StartServer () [0x00011] in /Users/mamcx/Downloads/BestSellerServer/Program.cs:14
at BestSeller.MainClass.Main (System.String[] args) [0x00006] in /Users/mamcx/Downloads/BestSellerServer/Program.cs:43

I check and have the licenses.licx. The same project compile fine on VS 2010.

Perhaps I need to forget about develop on mono/osx?

Are you saying you are building this in MonoDevelop/Mac? if so, and of the same project and same licx works when built in VS, this sounds like a bug in the Mono(Develop) license compiler. Try looking at the resulting .exe with Reflector or ILSpy - do you see a .licenses resource?

i gotta admit i’m not 100% up to date with Mono’s C# compiler’s support for licensing and what is supposed to work; i do now that they supposedly added the feature a while back, based on the licx compiler from Oxygene that Carlo contributed to Mono.

i would suggest contacting Mono support, as well, but i’ll also have someone from our side look into this, as well.

@mamcx: the problem is that while the Prism plugin does compile licenses, the C# plugin does not. There’s a bugreport for this but it’s not been implemented. There is a workaround for this though, you can use a pre-build action to call the license compiler (lc) and embed the resulting .resouces file as an embedded resource. (Make sure you gac all the RO, DA and Everwood dlls on Mono)

Hello

As Carlo already said, you need to manually embed compiled licenses into your application .exe

Here is a list of actions needed to build and run the Basic server (sample shipped with RemObjects SDK for .NET)

  1. Add Everwood, SDK and DataAbstract assemblies to GAC using “gacutil” command:
sudo gacutil -i RemObjects.InternetPack.dll
sudo gacutil -i RemObjects.SDK.dll
sudo gacutil -i RemObjects.SDK.Server.dll
sudo gacutil -i RemObjects.SDK.ZeroConf.dll
sudo gacutil -i RemObjects.SDK.ZLib.dll
sudo gacutil -i RemObjects.DataAbstract.dll
sudo gacutil -i RemObjects.DataAbstract.Linq.dll
sudo gacutil -i RemObjects.DataAbstract.Scripting.dll
sudo gacutil -i RemObjects.DataAbstract.Server.dll
sudo gacutil -i RemObjects.Everwood.dll
sudo gacutil -i RemObjects.Everwood.LicenseManager.exe
sudo gacutil -i RemObjects.SDK.Designtime.dll
sudo gacutil -i RemObjects.DataAbstract.Designtime.dll
  1. Download your licenses file from our site and put this file into the folder
~/.config/RemObjects Software/Licenses

with name, say, license.license (extension is important here)

Note that .config might not be visible in the Finder, so you’ll need to use the cp command to copy the file

  1. Compile the .licx file using command like
lc /target:ServerName.exe /complist:licenses.licx --load=RemObjects.SDK.dll --load=RemObjects.SDK.Server.dll

–load parameter should point to assembly (assemblies) mentioned in the licenses.licx file
ServerName.exe here should be replaced with actual server application assembly name

  1. Add the resulting
ServerName.exe.licenses
file into your server project as embedded resource. Make sure that its Resource ID is
ServerName.exe.licenses

Now you should be able to build and run the server application without any license exceptions

How exactly do that?

I register in the gac, copy the license and run:

lc /target:ServerName.exe /complist:licenses.licx --load=RemObjects.SDK.Server.dll

Get this error:

Mono License Compiler
Copyright © 2009 by RemObjects Software
Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘RemObjects.SDK.Server.dll’ or one of its dependencies. The system cannot find the file specified.
File name: 'RemObjects.SDK.Server.dll’
at (wrapper managed-to-native) System.Reflection.Assembly:LoadFrom (string,bool)
at System.Reflection.Assembly.LoadFrom (System.String assemblyFile) [0x00000] in :0
at LC.Program.Main (System.String[] args) [0x00000] in :0

–load= parameter should point to the assembly file, even i this assembly is GACed
Also please note that you have to ‘–load’ all assemblies mentioned in the licenses.licx file to be able to compile licenses file

Was not particulary evident how pass each one (I expected to be separated by ; o ,) but after see the code on http://mono.1490590.n4.nabble.com/License-compiler-for-mono-the-actual-tool-td1538865.html I do this:

lc /target:ServerName.exe /complist:/Users/mamcx/Proyectos/BestSeller/DataServer/BestSellerCloud/Properties/licenses.licx --load=RemObjects.Everwood.dll --load=RemObjects.SDK.Server.dll --load=RemObjects.DataAbstract.dll --load=RemObjects.DataAbstract.Server.dll --load=RemObjects.DataAbstract.Linq.dll --load=RemObjects.DataAbstract.Scripting.dll --load=RemObjects.DataAbstract.Web.dll --load=RemObjects.InternetPack.dll --load=RemObjects.SDK.ZeroConf.dll --load=RemObjects.SDK.ZLib.dll

However, I get this error:

Mono License Compiler
Copyright © 2009 by RemObjects Software
Exception during compiling /Users/mamcx/Proyectos/BestSeller/DataServer/BestSellerCloud/Properties/licenses.licx: 0
System.Exception: Unable to find assembly RemObjects.Everwood, Version=3.0.17.265, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
at LC.Program.CurrentDomain_AssemblyResolve (System.Object sender, System.ResolveEventArgs args) [0x00000] in :0
at System.AppDomain.DoAssemblyResolve (System.String name, Boolean refonly) [0x00000] in :0
at RemObjects.SDK.Designtime.RemObjectsSDKExternalLicenseGenerator.GenerateLicense (System.Type aType) [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
Exception during compiling /Users/mamcx/Proyectos/BestSeller/DataServer/BestSellerCloud/Properties/licenses.licx: 0
System.Exception: Unable to find assembly RemObjects.Everwood, Version=3.0.17.265, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
at LC.Program.CurrentDomain_AssemblyResolve (System.Object sender, System.ResolveEventArgs args) [0x00000] in :0
at System.AppDomain.DoAssemblyResolve (System.String name, Boolean refonly) [0x00000] in :0
at RemObjects.SDK.Designtime.RemObjectsSDKExternalLicenseGenerator.GenerateLicense (System.Type aType) [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
Exception during compiling /Users/mamcx/Proyectos/BestSeller/DataServer/BestSellerCloud/Properties/licenses.licx: 0
System.Exception: Unable to find assembly RemObjects.Everwood, Version=3.0.17.265, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
at LC.Program.CurrentDomain_AssemblyResolve (System.Object sender, System.ResolveEventArgs args) [0x00000] in :0
at System.AppDomain.DoAssemblyResolve (System.String name, Boolean refonly) [0x00000] in :0
at RemObjects.DataAbstract.Designtime.DataAbstractExternalLicenseGenerator.GenerateLicense (System.Type aType) [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
Exception during compiling /Users/mamcx/Proyectos/BestSeller/DataServer/BestSellerCloud/Properties/licenses.licx: 0
System.Exception: Unable to find assembly RemObjects.Everwood, Version=3.0.17.265, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
at LC.Program.CurrentDomain_AssemblyResolve (System.Object sender, System.ResolveEventArgs args) [0x00000] in :0
at System.AppDomain.DoAssemblyResolve (System.String name, Boolean refonly) [0x00000] in :0
at RemObjects.DataAbstract.Designtime.DataAbstractExternalLicenseGenerator.GenerateLicense (System.Type aType) [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

Everwood is already there ( I cd into a folder with all the RO files mentioned). The only thing I can imagine is that the version I have is 3.0.21.293 and the error ask for 3.0.17.265

Seems you have a version conflict between actually GACed assembly and needed one.

Usual cause of such exceptions are different versions of assemblies RemObjects.Everwood.dll and RemObjects.Everwood.LicenseManager.exe

Also RemObject.SDK.Designtime and RemObject.DataAbstract.Designtime assemblies reference RemObjects.Everwood.dll (and its version should match as well)

To avoid such problems you need to GAC Everwood and Data Abstact assemblies shipped together. The easiest way to do this is to install Data Abstract on a clean VM ad took all needed assemblies from there.

Ok, now the file is generated… but how embed it?

I right-click in ServerName.exe.licenses, select Embed as resource and in the properties put the id as ServerName.exe.licenses.

However get the same error

Seems you’ve missed the last (but not the least) step:

4. Add the resulting
ServerName.exe.licenses
file into your server project as embedded resource. Make sure that its Resource ID is
ServerName.exe.licenses

Now you should be able to build and run the server application without any license exceptions

MonoDevelop adds new resource with Recourse ID like

ServerName.ServerName.exe.licenses

Another possible cause is that server name you used in lc call (/target parameter) doesn’t match with the actual name of your application (my bad, I had to mention that ServerName in the lc call sample should be replaced with actual server name. I updated my post)

I’m getting fails again. I update to the last stable version, update all dlls, reput in the gac, and compile sucesfully the license by command line. However I get:

Unhandled Exception: System.ComponentModel.LicenseException: A system exception has occurred.
at RemObjects.SDK.ROLicenseProvider.GetLicense (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, Boolean allowExceptions) [0x00000] in :0
at System.ComponentModel.LicenseManager.privateGetLicense (System.Type type, System.Object instance, Boolean allowExceptions, System.ComponentModel.License& license) [0x00048] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.ComponentModel/LicenseManager.cs:191
at System.ComponentModel.LicenseManager.Validate (System.Type type, System.Object instance) [0x00002] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.ComponentModel/LicenseManager.cs:169
at RemObjects.SDK.Server.ServerChannel…ctor (Boolean allowMultipleDispatchers) [0x00000] in :0
at RemObjects.SDK.Server.HttpServerChannel…ctor (Boolean allowMultipleDispatchers) [0x00000] in :0
at RemObjects.SDK.Server.IpHttpServerChannel…ctor () [0x00000] in :0
at RemObjects.SDK.Server.IpHttpServerChannel…ctor (IContainer container) [0x00000] in :0
at (wrapper remoting-invoke-with-check) RemObjects.SDK.Server.IpHttpServerChannel:.ctor (System.ComponentModel.IContainer)
at BestSellerCloud.ROServer.InitializeComponent () [0x00016] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/ROServer.Designer.cs:33
at BestSellerCloud.ROServer…ctor () [0x00006] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/ROServer.cs:25
at BestSellerCloud.ROServer…ctor (IDAServerLog presenter) [0x00000] in :0
at (wrapper remoting-invoke-with-check) BestSellerCloud.ROServer:.ctor (BestSellerCloud.IDAServerLog)
at BestSellerCloud.BestSellerApp.startApp () [0x00000] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/CloudServer.cs:62
at BestSellerCloud.BestSellerApp.RunAsWindowsService () [0x00000] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/CloudServer.cs:86
at RemObjects.SDK.Server.ApplicationServer.RunAsMonoDaemon () [0x00000] in :0
at RemObjects.SDK.Server.ApplicationServer.RunMonoDaemon () [0x00000] in :0
at RemObjects.SDK.Server.ApplicationServer.Run (System.String[] arguments) [0x00000] in :0
at BestSellerCloud.BestSellerCloudMain.Main (System.String[] args) [0x00031] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/Main.cs:16
[ERROR] FATAL UNHANDLED EXCEPTION: System.ComponentModel.LicenseException: A system exception has occurred.
at RemObjects.SDK.ROLicenseProvider.GetLicense (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, Boolean allowExceptions) [0x00000] in :0
at System.ComponentModel.LicenseManager.privateGetLicense (System.Type type, System.Object instance, Boolean allowExceptions, System.ComponentModel.License& license) [0x00048] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.ComponentModel/LicenseManager.cs:191
at System.ComponentModel.LicenseManager.Validate (System.Type type, System.Object instance) [0x00002] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.ComponentModel/LicenseManager.cs:169
at RemObjects.SDK.Server.ServerChannel…ctor (Boolean allowMultipleDispatchers) [0x00000] in :0
at RemObjects.SDK.Server.HttpServerChannel…ctor (Boolean allowMultipleDispatchers) [0x00000] in :0
at RemObjects.SDK.Server.IpHttpServerChannel…ctor () [0x00000] in :0
at RemObjects.SDK.Server.IpHttpServerChannel…ctor (IContainer container) [0x00000] in :0
at (wrapper remoting-invoke-with-check) RemObjects.SDK.Server.IpHttpServerChannel:.ctor (System.ComponentModel.IContainer)
at BestSellerCloud.ROServer.InitializeComponent () [0x00016] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/ROServer.Designer.cs:33
at BestSellerCloud.ROServer…ctor () [0x00006] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/ROServer.cs:25
at BestSellerCloud.ROServer…ctor (IDAServerLog presenter) [0x00000] in :0
at (wrapper remoting-invoke-with-check) BestSellerCloud.ROServer:.ctor (BestSellerCloud.IDAServerLog)
at BestSellerCloud.BestSellerApp.startApp () [0x00000] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/CloudServer.cs:62
at BestSellerCloud.BestSellerApp.RunAsWindowsService () [0x00000] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/CloudServer.cs:86
at RemObjects.SDK.Server.ApplicationServer.RunAsMonoDaemon () [0x00000] in :0
at RemObjects.SDK.Server.ApplicationServer.RunMonoDaemon () [0x00000] in :0
at RemObjects.SDK.Server.ApplicationServer.Run (System.String[] arguments) [0x00000] in :0
at BestSellerCloud.BestSellerCloudMain.Main (System.String[] args) [0x00031] in /Users/mamcx/Proyectos/BestSeller/Cloud/src/Main.cs:16

Ok, with the libs at version 6.0.55.957 this work, but with the version 6.0.61.1033 happend the previous error above.

I have last MONO/MONODEVELOP as today.

This is my GAC:

RemObjects.DataAbstract, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.DataAbstract.Designtime, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.DataAbstract.Linq, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.DataAbstract.Scripting, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.DataAbstract.Server, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.DataAbstract.Web, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.Everwood, Version=3.0.31.355, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.InternetPack, Version=2.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.SDK, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.SDK.Designtime, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.SDK.Server, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.SDK.ZLib, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.SDK.ZeroConf, Version=6.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098
RemObjects.Script, Version=2.0.61.1033, Culture=neutral, PublicKeyToken=3df3cad1b7aa5098

This is the compilation

cd bin && lc /target:BestSellerCloud.exe /complist:…/Properties/licenses.licx --load=…/bin/RemObjects.DataAbstract.dll --load=…/bin/RemObjects.DataAbstract.Linq.dll --load=…/bin/RemObjects.DataAbstract.Scripting.dll --load=…/bin/RemObjects.DataAbstract.Server.dll --load=…/bin/RemObjects.DataAbstract.Web.dll --load=…/bin/RemObjects.InternetPack.dll --load=…/bin/RemObjects.Script.dll --load=…/bin/RemObjects.SDK.dll --load=…/bin/RemObjects.SDK.Server.dll --load=…/bin/RemObjects.SDK.ZeroConf.dll --load=…/bin/RemObjects.SDK.ZLib.dll

Hello.

Can you provide compiled assembly to us?

Thanks in advance.

Ok, I send the mail with the binaries.

Hello

Thanks for the binaries. I have examined Resources part of the .exe file. While .exe.licenses resource is present there it doesn’t seems that it was generated correctly.

It contains compiled licenses for assemblies of version 6.0.55.957 and 6.0.53.935 while the application itself references 6.0.61.1033.

.NET license check (one that raises the System.ComponentModel.LicenseException exception) uses strong assembly names that include assembly version. Thus it cannot accept as valid license compiled for version 6.0.55.957 when class being instantiated comes from assembly version 6.0.61.1033 .

MonoDevelop doesn’t handle licenses.licx file automatically as Visual Studio does. So you have to regenerate the .licenses file as described above. This should fix the issue.