2011-06-08 89 views
1

我有兩個類庫包含使用窗口和用戶控件一些演示的一部分。假設它是Presentation1和Presentation2。我還有一個是Common的CL,並且兩個Presentation庫都引用它。在通用庫中,我已經指定了一些自定義轉換器。我在兩個演示文稿中都使用它們,但在Presentation1中一切正常,但在Presentation2中,在設計時可以看到相同的轉換器,但在運行時我收到一個異常:使用CustomConverters拋出異常

'在'System.Windows.StaticResourceExtension'上提供值引發異常。 「行號「55」和行位置「35」。

如果我提出這些轉換器的Presentation2和自身引用他們,那麼他們將工作。

任何建議請什麼地方出錯了?提前致謝。

更新:

我Presentation2 XAML:

<UserControl x:Class="MyProject.PresentationCL2.Presentation.IssuedView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:Converters="clr-namespace:MyProject.Common.Presentation.Converters;assembly=MyProject.Common"> 
    <UserControl.Resources> 
     <ResourceDictionary> 
      <Converters:IntToStringConverter x:Key="IntToStringConverter" /> 
     </ResourceDictionary> 
    </UserControl.Resources> 
    ... 
    <ComboBox Margin="0, 10" 
       Grid.Row="1" Grid.Column="1" 
       ItemsSource="{Binding Path=SomeCollection}" 
       SelectedItem="{Binding Path=SomeCollectionSelectedValue, Converter={StaticResource IntToStringConverter}, Mode=TwoWay}" 
            /> 
    ... 
</UserControl> 

Presentation1 XAML看起來相同,但做工精細。 Presentation2在Converter從StaticResources引用的那一行中引發一個偏移。

另外值得注意的是,當我將這個IntToStringConverter移動到我的Presentation2庫中(並且它在Presentation1中開始正常工作時)引入了它的代碼,我使用了從同一個Common Assembly中引用的許多類,它也可以工作。

UPDATE2:

我試圖使用DebugView中處理此異常和結果提供如下:

[1]異常消息:System.Windows.StaticResourceExtension「上提供值 '' 引發了例外。'行號「48」和行位置「35」。
[2]異常幫助鏈接:
[3]異常源:PresentationFramework
[4]異常堆棧跟蹤:在System.Windows.Markup.XamlReader.RewrapException(例外五,IXamlLineInfo lineInfo,烏里基本URI)
[5 ]在System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader,IXamlObjectWriterFactory writerFactory,布爾skipJournaledProperties,對象rootObject,XamlObjectWriterSettings設置,烏里基本URI)
[6]在System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader,布爾skipJournaledProperties,對象rootObject,XamlAccessLevel ACCESSLEVEL,烏里基本URI)
[7]在System.Windows.Markup.XamlReader.LoadBaml(流S tream,ParserContext parserContext,Object parent,Boolean closeStream)
[8] at System.Windows.Application.LoadComponent(Object component,Uri resourceLocator)
[9] at SettingsView.InitializeComponent()in .. \ Presentation2 \ Presentation \ presentation2. Settings..xaml:line 1
[10]在SettingsView..ctor(TobiiEyeTrackingSettingsViewModel viewModel)in .. \ Presentation \ SettingsView.xaml.cs:line 14
[11]在Presentation2.MainClass.ShowSetupDialog(Object varHwndParent )在.. \ Presentation2 \ MainClass.cs:線171
[12] InnerExceptionMessage:該方法或操作未實現。
[13] InnerExceptionStackTrace:在System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType,Int16的TYPEID)
[14]在System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16的TYPEID)
[15]在系統.Windows.Baml2006.Baml2006Reader.Process_ElementStart()
[16]在System.Windows.Baml2006.Baml2006Reader.ReadObject(KeyRecord記錄)
[17]在System.Windows.ResourceDictionary.CreateObject(KeyRecord鍵)
[18 ]在System.Windows.ResourceDictionary.RealizeDeferContent(Object key,Object & value,Boolean & canCache)
[19]在System.Windows.ResourceDictionary.GetValueWithoutLock(對象鍵,布爾& canCache)
[20]在System.Windows.ResourceDictionary.GetValue(對象鍵,布爾& canCache)
[21]在System.Windows .ResourceDictionary.Lookup(對象鍵,布爾allowDeferredResourceReference,布爾mustReturnDeferredResourceReference)
[22]在System.Windows.StaticResourceExtension.FindResourceInEnviroment(的IServiceProvider的ServiceProvider,布爾allowDeferredReference,布爾mustReturnDeferredResourceReference)
[23]在System.Windows.StaticResourceExtension.TryProvideValueInternal (IServiceProvider serviceProvider,布爾allowDeferredReference,布爾mustReturnDeferredR esourceReference)
[24]在System.Windows.StaticResourceExtension.ProvideValueInternal(的IServiceProvider的ServiceProvider,布爾allowDeferredReference)
[25]在System.Windows.StaticResourceExtension.ProvideValue(的IServiceProvider的ServiceProvider)
[26]在MS.Internal.Xaml .Runtime.ClrObjectRuntime.CallProvideValue(的MarkupExtension我的IServiceProvider的ServiceProvider)

它值得補充的是MainClass提到的第11行是標記有ComVisible特性類系統registred和實施專用接口(可以說ICOMInterface)其中:

[Guid("... guid here ...")] 
[ComVisible(true)] 
public class MainClass : ICOMInterface 
{ 
    ... 

    public void ShowSetupDialog(object varHwndParent) 
    { 
     SettingsView view = new SettingsView(); 
     view.ShowDialog(); 
    } 

    ... 
} 

如果我不會處理這個異常,然後程序,它通過調用這個ShowSetupDialog實現iterface返回HRESULT 80131501這是COR_E_SYSTEM這是.NET中構造一個SystemException

回答

0

你應該能夠鑽到異常,並獲得更多的信息 - 請嘗試發佈你找到的任何內容。

如果沒有這些信息,我只能假設您的Presentation2庫沒有對您的公共庫的引用。

+0

Presentation2對公共庫有參考。我已經爲這個問題^ _ ^提供了更多的信息 – PompolutZ 2011-06-08 11:06:37