ArcObjects SDK .NET license initialization

1051
5
Jump to solution
03-18-2021 08:54 AM
DiegoGuidi1
New Contributor II

Dear All, I'm trying to understand if it's possible to use code developed with ArcObjects SDK for .NET in an environment where only ArcGIS Enterprise (Server+Portal) is installed.

Basically I need to develop a task (as a windows service or as a scheduled task) that periodically extracts data from a geodatabase published by ArcGIS Enterprise.

I planned to use ArcObjects SDK for .NET, but the license initialization code that I'm using is working on my test environment (where ArcMap is installed) but not on the server environment (where ArcGIS Server and ArcGIS Portal are installed).

Any suggestion?

Below the code I'm using to check for the license:

 

 

 

AoInitialize license = null;
try
{
	Console.WriteLine("License check started");
	var b = RuntimeManager.Bind(ProductCode.Server);
	// FAlSE ON BOTH ENVIRONMENTS: dev and produ
	Console.WriteLine($"RuntimeManager.Bind(ProductCode.Server): {b} => {w.Elapsed}");
	if (!b)
	{
		// TRUE on dev env and FALSE on prod env
		b = RuntimeManager.Bind(ProductCode.Desktop);
		Console.WriteLine($"RuntimeManager.Bind(ProductCode.Desktop): {b} => {w.Elapsed}");
	}
	if (!b)
	{
		// FALSE on prod env
		b = RuntimeManager.Bind(ProductCode.Engine);
		Console.WriteLine($"RuntimeManager.Bind(ProductCode.Engine): {b} => {w.Elapsed}");
	}
	if (!b)
	{
		const string err = "RuntimeManager failed to bind to any product!";
		Console.WriteLine(err);
		return;
	}

	// code not run on production environment
	esriLicenseProductCode[] codes = new esriLicenseProductCode[]
	{
		esriLicenseProductCode.esriLicenseProductCodeArcServer,
		esriLicenseProductCode.esriLicenseProductCodeBasic,
		esriLicenseProductCode.esriLicenseProductCodeStandard, // detected on dev env
		esriLicenseProductCode.esriLicenseProductCodeAdvanced,
		esriLicenseProductCode.esriLicenseProductCodeEngine,
		esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB,
	};

	license = new AoInitialize();
	foreach (esriLicenseProductCode code in codes)
	{
		esriLicenseStatus status = license.IsProductCodeAvailable(code);
		if (status == esriLicenseStatus.esriLicenseAvailable)
		{
			Console.WriteLine($"Code '{code}' available... => {w.Elapsed}");
			status = license.Initialize(code);
			if (status == esriLicenseStatus.esriLicenseAlreadyInitialized ||
				status == esriLicenseStatus.esriLicenseCheckedOut)
			{
				Console.WriteLine($"Code '{code}' initialized => {w.Elapsed}");
				break;
			}
			else
			{
				Console.WriteLine($"Code '{code}' NOT initialized! => {w.Elapsed}");
			}
		}
		else
		{
			Console.WriteLine($"Code '{code}' NOT available! => {w.Elapsed}");
		}
	}
}
catch (Exception ex)
{
	Console.WriteLine($"Exception thrown :( => {w.Elapsed}");
	Console.WriteLine(ex);
}
finally
{
	license?.Shutdown();
	AOUninitialize.Shutdown();
	Console.WriteLine($"Shutdown completed => {w.Elapsed}");
}

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
HanhanSun1
Esri Contributor

It's possible. Try building the project with either *64bit platform or AnyCPU with "Prefer 32-bit" unchecked. 

HanhanSun1_0-1616103951264.png

 

Once the project is built properly, the code should be able to bind server license (Bind(ProductCode.Server)) and checkout server license (Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer)).

View solution in original post

5 Replies
HanhanSun1
Esri Contributor

It's possible. Try building the project with either *64bit platform or AnyCPU with "Prefer 32-bit" unchecked. 

HanhanSun1_0-1616103951264.png

 

Once the project is built properly, the code should be able to bind server license (Bind(ProductCode.Server)) and checkout server license (Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer)).

DiegoGuidi1
New Contributor II

@HanhanSun1 wrote:

It's possible. Try building the project with either *64bit platform or AnyCPU with "Prefer 32-bit" unchecked. 

HanhanSun1_0-1616103951264.png

 

Once the project is built properly, the code should be able to bind server license (Bind(ProductCode.Server)) and checkout server license (Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer)).


Thanks a lot for the reply, actually this is what I'm expecting. I will try with different compilation strategies to see what happens.

Something that it's not clear to me is that AFAIK ArcObjects .NET is 32bit, at least on my dev env (I already tried sone experiments and I receive BadImageFormatException when trying to open a shapefile from a 64bit process), so maybe there's a 64 bit version I can use to develop the solution in my dev environment?

0 Kudos
DiegoGuidi
New Contributor III

tested right now in a different environment (another dev environment) with arcobjects sdk 10.8.1 and it worked as you mentioned. in my standard dev environment I had arcobjects 10.5, but both are x64 environmetns with Win10 OS. So I suppose that the different behaviour depends of the SDK version...

anyway, thanks for the suggestion!

0 Kudos
DiegoGuidi
New Contributor III

I actually tried but license checking code doesn't work with 64bit compilation

0 Kudos
DiegoGuidi1
New Contributor II

just to add a bit of context, the suggested code works in 64bit mode, and my test code that failed in 64bit mode was related to the "ComReleaser" in the "ESRI.ArcGIS.ADF.Connection.Local" assembly, that probably isn't working on 64 bit. removing this reference, the arcobjects code that "do the actual work" (besides checking the license) works as expected.

0 Kudos