捆绑MahApps.Metro DLL会导致System.Windows.Markup.XamlParseException

时间:2014-07-15 16:16:54

标签: c# wpf dll bundle mahapps.metro

根据this topic,您可以将MahApps.Metro.dllSystem.Windows.Interactivity.dll嵌入到项目中,并将它们捆绑到1个exe中。 不幸的是,这会在提到的Program.cs中App.Main();引起异常。

  

PresentationFramework.dll中的System.Windows.Markup.XamlParseException

     

附加信息:行号" 8"和位置" 18" System.Windows.ResourceDictionary.Source

我查了demo-project只是为了找到我已经拥有的完全相同的项目设置。 试图捕获InnerException:

  

System.IO.FileNotFoundException:文件或程序集" MahApps.Metro,Culture = neutral"找不到

Dateiname: 'MahApps.Metro, Culture=neutral'
bei System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
bei System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
bei System.Reflection.Assembly.Load(AssemblyName assemblyRef)
bei System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(String assemblyName, String assemblyVersion, String assemblyKey)
bei MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(Uri uri, String& partName, Boolean& isContentFile)
bei MS.Internal.AppModel.ResourceContainer.GetPartCore(Uri uri)
bei System.IO.Packaging.Package.GetPart(Uri partUri)
bei System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
bei System.IO.Packaging.PackWebResponse.get_ContentType()
bei MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
bei MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
bei System.Windows.ResourceDictionary.set_Source(Uri value)
bei MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)

为了说清楚,我从演示项目中复制了2个dll并将它们粘贴到另一个extern" lib"文件夹,然后将它们作为链接添加到实习DllsAsResource文件夹中,并在我的项目中引用它们。

1 个答案:

答案 0 :(得分:0)

好的,我自己发现了这个问题。 似乎Assembly NameDefault Namespace(项目菜单 - >属性)必须完全相同。我的不同,大会名称包含'!'在默认命名空间中用'_'替换,从而产生此错误。

您可以在编译后重命名您的应用程序。