WPF上Arc Lisence的有关问题
WPF下Arc Lisence的问题
代码如下:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
//using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
namespace DigitalHomeDesktop
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
/// 初始化权限
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
InitializeEngineLincense();
}
private void InitializeEngineLincense()
{
AoInitialize aoi = new AoInitializeClass();
esriLicenseProductCode productcode = esriLicenseProductCode.esriLicenseProductCodeEngine;
if (aoi.IsProductCodeAvailable(productcode) ==esriLicenseStatus.esriLicenseAvailable)
{
aoi.Initialize(productcode);
}
//throw new NotImplementedException();
}//设置权限方法
}
}
和ArcGIS的帮助文档里的例子基本上一样,就是不知道为什么还报错。
异常信息如下:
未处理 System.Runtime.InteropServices.COMException
Message=ArcGIS product not specified. You must first bind to an ArcGIS version prior to using any ArcGIS components.
Source=esriSystem.AoInitialize
ErrorCode=-2147221002
StackTrace:
在 ESRI.ArcGIS.esriSystem.AoInitializeClass.IsProductCodeAvailable(esriLicenseProductCode ProductCode)
在 DigitalHomeDesktop.App.InitializeEngineLincense() 位置 E:\ArcGIS\DigitalHomeDesktop\DigitalHomeDesktop\App.xaml.cs:行号 29
在 DigitalHomeDesktop.App.OnStartup(StartupEventArgs e) 位置 E:\ArcGIS\DigitalHomeDesktop\DigitalHomeDesktop\App.xaml.cs:行号 22
在 System.Windows.Application.<.ctor>b__0(Object unused)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
在 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
在 System.Threading.ExecutionContext.runTryCode(Object userData)
在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Windows.Threading.DispatcherOperation.Invoke()
在 System.Windows.Threading.Dispatcher.ProcessQueue()
在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
在 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
在 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
在 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
在 System.Windows.Threading.Dispatcher.Run()
在 System.Windows.Application.RunDispatcher(Object ignore)
在 System.Windows.Application.RunInternal(Window window)
在 System.Windows.Application.Run(Window window)
在 System.Windows.Application.Run()
在 DigitalHomeDesktop.App.Main() 位置 E:\ArcGIS\DigitalHomeDesktop\DigitalHomeDesktop\obj\x86\Debug\App.g.cs:行号 0
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
------解决方案--------------------
你用的是arcgis10吧?
提示信息:ArcGIS product not specified. You must first bind to an ArcGIS version prior to using any ArcGIS components.
Source=esriSystem.AoInitialize
在注册前加多下面几句试试:
if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine))
{
if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop))
{
System.Console.WriteLine("This application could not load the correct version of ArcGIS.");
return;
}
}