2014-06-15 36 views
0

啓動我的WPF應用程序,並試圖顯示特定控制我收到此異常:WPF C# - 無法加載文件的.resources

「FileNotFoundException異常 - 無法加載文件或程序集」 Xceed.WPF.Toolkit.resources,版本= 2.0.0.0,文化= IT,IT ......」

我知道這似乎已經討論過一個問題,但我的問題是有點更具體。

我有我的應用程序(Wolf.exe),其使用插件系統。插件系統從位於擴展應用程序文件夾內的外部DLL加載插件類(該文件夾位於相同的位置.exe的級別)。插件能夠加載額外的資源,比如xaml字典,並指定自定義樣式來擴展基本組件。

一個這個插件/組件(FSMExtension.dll)加載額外的XAML資源以這種方式:

  FileStream oFileStream = new FileStream(filename, FileMode.Open); 
      if (oFileStream != null) 
      { 
       ResourceDictionary oResourceDictionary = (ResourceDictionary)XamlReader.Load(oFileStream); 
       if (oResourceDictionary != null) 
       { 
        Application.Current.Resources.MergedDictionaries.Add(oResourceDictionary); 
       } 
      } 
      oFileStream.Close(); 

FSMExtension.dll對 「擴展WPF工具包™社區版」 的依賴(http://wpftoolkit.codeplex.com/documentation)事業它需要一個PropertyGrid組件。所得XAML也有類似的方面:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:converters="clr-namespace:WolfLib.UI.Converters;assembly=WolfLib" 
       xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid;assembly=Xceed.Wpf.Toolkit"> 
<converters:BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" IsHidden="false" TriggerValue="false"></converters:BooleanToVisibilityConverter> 
<Style x:Key="FSMBlockStyle" TargetType="ContentControl"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <xctk:PropertyGrid Grid.Row="5" Grid.ColumnSpan="2" Margin="5 0 5 5" Visibility="{Binding ElementName=PropertyToggleButton, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}" 
            ShowSummary="false" 
            IsCategorized="true" 
            ShowAdvancedOptions="false"             
            IsReadOnly="false" 
            ShowSortOptions="false" 
            ShowSearchBox="false" 
            ShowTitle="false" 
            AutoGenerateProperties="false" 
            MaxWidth="300"> 
        <xctk:PropertyGrid.PropertyDefinitions> 
         <xctk:PropertyDefinition TargetProperties="Name,Type,MainController,Views,ControllerBehaviours,ControllerParams"/> 
        </xctk:PropertyGrid.PropertyDefinitions> 
       </xctk:PropertyGrid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

當我申請的特定樣式我控制我收到上述異常。如果我嘗試直接使用我的應用程序中的PropertyGrid控件(在MainWindow.xaml上),則不會發生此異常。這個問題也很奇怪,因爲我沒有任何這種程序集的.resources.dll文件。

我發現解決這個問題的唯一方法是爲「Extended WPF Toolkit™Community Edition」指定默認文化程序集並重建它。

此修補程序適用於具有「IT-IT」語言/文化的我的機器配置。如果我使用不同文化(即en-US)的不同機器啓動我的應用程序,則異常將再次拋出。

有沒有處理這類問題的具體方法?如果您需要更多信息,請與我們聯繫。

回答

1

我不知道Xceed是如何工作的,但是當使用多種文化時,程序集必須進行修飾以指示默認文化。否則,.NET運行時會抱怨無法找到資源文件。它會在AssembyInfo.cs每個消耗組件:

在桌面應用程序中,NeutralResourcesLanguageAttribute屬性 通知應用程序的默認區域性的資源管理器及其資源的 位置。默認情況下,資源被嵌入 主應用程序集中,您可以按如下所示使用該屬性。

聲明看起來像這樣...

[assembly: NeutralResourcesLanguage("en-GB")] 

其中 「EN-GB」 指定默認的。如果找不到它,裝配的裝飾看起來像這樣...

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information 
// associated with an assembly. 
[assembly: AssemblyTitle("MultiLanguage")] 
[assembly: AssemblyDescription("")] 
[assembly: AssemblyConfiguration("")] 
[assembly: AssemblyCompany("")] 
[assembly: AssemblyProduct("MultiLanguage")] 
[assembly: AssemblyCopyright("Copyright © 2014")] 
[assembly: AssemblyTrademark("")] 
[assembly: AssemblyCulture("")] 
[assembly: NeutralResourcesLanguage("en-GB")] 

的文檔是在這裏http://msdn.microsoft.com/en-us/library/system.resources.neutralresourceslanguageattribute.aspx

並沒有與源這裏https://tcimultilanguage.codeplex.com/

+0

我已經做了一個WPF參考應用。我已經通過添加中性資源語言來裝飾圖書館,但它只有在我將異常文化放在例外情況下(在我的系統中是「IT-IT」)時才起作用。如果我在另一臺機器上啓動應用程序,正如我上面所說的,使用不同的文化,我再次收到異常(帶有「en-US」)。我很確定有一件事我根本沒有得到。我必須爲每種文化構建第三方dll嗎? – st4lk3r87

+0

也許真正的問題是,我如何禁用多種文化設置?有沒有辦法做到這一點? – st4lk3r87

+0

你確定裝飾在每個消費組裝中嗎?另外,您可能需要設置所謂的UltimateResourceFallbackLocation。您還可以查看.csproj文件的元素。我不知道Xceed或其他組件是什麼,但根據你寫的內容,你可能需要重建。 –