目錄
[Map 3D開發實戰系列] Map Resource Explorer 背景介紹--Kick off
[Map 3D開發實戰系列] Map Resource Explorer 之二-- 運行和調試
[Map 3D開發實戰系列] Map Resource Explorer 之三-- 添加AutoCAD風格的Palette介面
如果你已經隨著我們前面的文章開始建立基於WPF技術的Map 3D自訂介面的話,你可能會遇到一個比較棘手的問題,就是在Visual Studio 2008中的WPF編輯器中,可視化介面總是顯示錯誤,從而不能想Winform介面設計一樣拖控制項進去。更麻煩的是兩xaml編輯器的智能提示都沒有了,這對我這樣的WPF菜鳥來說真是要命啊!
每次在Visual Studio 2008中開啟xaml檔案,總是顯示下面的錯誤資訊:
An Unhandled Exception has occured.
A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context.
at System.Reflection.Module.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType)
at System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at MS.Internal.Xaml.ReflectionProjectNode.BuildSubsumption()
at MS.Internal.Xaml.ReflectionProjectNode.SubsumingNamespace(Identifier identifier)
at MS.Internal.Xaml.XmlElement.BuildScope(PrefixScope parentScope, IParseContext context)
at MS.Internal.Xaml.XmlElement.FindElementType(PrefixScope parentScope, IParseContext context)
at MS.Internal.DocumentTrees.Markup.XamlSourceDocument.get_RootType()
at Microsoft.Windows.Design.Documents.Trees.MarkupDocumentTreeManager.get_RootType()
at Microsoft.Windows.Design.Documents.MarkupDocumentManager.CalculateLoadErrorState()
at Microsoft.Windows.Design.Documents.MarkupDocumentManager.get_LoadState()
at MS.Internal.Host.PersistenceSubsystem.Load()
at MS.Internal.Host.Designer.Load()
at MS.Internal.Designer.VSDesigner.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.Load()
at MS.Internal.Designer.DesignerPane.LoadDesignerView()
Could not load file or assembly 'acmgd, Version=18.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at System.ModuleHandle.ResolveType(Int32 typeToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.Module.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
這其實是Map 3D 2011的一個bug。前面的文章中介紹了,我們要開發Map 3D 應用程式,需要添加下列的Map 3D相關引用:
Map 3D相關程式集:
Autodesk.Map.Platform.dll
Autodesk.Map.Platform.Core.dll
Autodesk.Map.Platform.Utils.dll;
Autodesk.Gis.Map.Shared.dll;
OSGeo.MapGuide.Foundation.dll
OSGeo.MaoGuide.PlatformBase.dll
但引用的上面的Map 3D相關程式集,就會造成Visual Studio 的WPF編輯器工作不正常。當然你可以使用Blend,XamlPad等其他工具來編輯Xaml介面,但對於我們簡單的介面設計來說,Blend有點大材小用,而且學習這個軟體也得花不少時間。
解決的辦法就是在設計介面是,暫時把上面的Map 3D相關程式集的引用移除,這樣WPF介面編輯器就可以正常工作了。編輯好了介面,需要編譯運行時,再重新把這些程式集的引用加進來就行了。Visual Studio引用對話方塊的Recent選項卡可以快速的幫我找到最近用過的程式集,還是很方便的。
好了,先到這裡,現在你可以開始設計你的基於Map 3D應用程式WPF介面了。
Cheers,
峻祁連