I want to check all installed products, and bind to the first available one. Now I have a machine with an expired Engine license, but with a valid Desktop license. The following code should do the trick, but it doesn't. If the first checked license is not available, all others fail as well. If I change the order of the list, e.g. Desktop comes first, it works, if Engine is first, it doesn't.
foreach (var product in new[] {ProductInfo.Engine, ProductCode.Desktop, ProductCode.Server}) { try { RuntimeManager.BindLicense(product, LicenseLevel.Standard); Console.WriteLine("Arcgis product {0} is licensed", product); return true; } catch (RuntimeManagerException e) { Console.WriteLine("Arcgis product {0} is not licensed", product); Console.WriteLine(e.Message); } } return false;
Any idea why this doesn't work?
No idea why it would fail but have you tried the alternate overloaded method of BindLicence(productcode)? May be that will work?
check with Bind (BindLicense bind and initialize)
if (!RuntimeManager.Bind(ProductCode.Engine))
{
if (!RuntimeManager.Bind(ProductCode.Desktop))
{
MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
return;
}
}
Thanks to both of you for your answers, but they didn't solve my problem. I tried both overloads of BindLicense(), but that makes no difference. In fact, according to the docs, BindLicense(product) binds to a Standard license level by default, so my code is equivalent to it.
Bind() doesn't raise errors, but it doesn't check out a license either, so it's no good.
Bind binds to product but then you need initialize. It doesn't raise error if it doesn't bind product : it return false. While BindLicense is void. You need target project in x86
if (RuntimeManager.Bind(ProductCode.Server))
{
IAoInitialize aoInit = new AoInitializeClass();
esriLicenseStatus a = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
}