代码如下:
- C# code
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)