使用在其他程序集中指定的CustomConverters会引发异常

时间:2011-06-08 08:29:56

标签: c# wpf com-interop

我有两个类库,其中包含一些使用窗口和用户控件的演示文稿部分。假设它是Presentation1和Presentation2。我还有一个CL是Common,两个Presentation库都引用它。在Common库中,我已经指定了许多自定义转换器。我在两个演示文稿中都使用它们但在Presentation1中一切正常,但在Presentation2中,相同的转换器在设计时可见,但在运行时我收到异常:

'在'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在该行引发了一个excantition,其中Converter引用了StaticResources。

另外值得注意的是,当我将这个IntToStringConverter移动到我的Presentation2库中(并且它在Presentation1中开始正常工作时)包含其代码我使用了从同一个Common程序集引用的许多类,它也可以工作。

UPDATE2:

我尝试使用DebugView处理此异常,结果如下:

[1]异常消息:'在'System.Windows.StaticResourceExtension'上提供值引发异常。行号'48'和行位置'35' [2]例外帮助链接:
[3]例外来源:PresentationFramework
[4]异常StackTrace:在System.Windows.Markup.XamlReader.RewrapException(例外e,IXamlLineInfo lineInfo,Uri baseUri)
[5]在System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader,IXamlObjectWriterFactory writerFactory,Boolean skipJournaledProperties,Object rootObject,XamlObjectWriterSettings settings,Uri baseUri)
[6]在System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader,Boolean skipJournaledProperties,Object rootObject,XamlAccessLevel accessLevel,Uri baseUri)
[7]在System.Windows.Markup.XamlReader.LoadBaml(Stream stream,ParserContext parserContext,Object parent,Boolean closeStream)
[8]在System.Windows.Application.LoadComponent(对象组件,Uri resourceLocator)上 [9]在.. \ Presentation2 \ Presentation \ presentation \ SettingsView.xaml中的SettingsView.InitializeComponent()中:第1行 [10]在.. \ Presentation \ SettingsView.xaml.cs中的SettingsView..ctor(TobiiEyeTrackingSettingsViewModel viewModel):第14行 [11]在.. \ Presentation2 \ MainClass.cs中的Presentation2.MainClass.ShowSetupDialog(Object varHwndParent):第171行
[12] InnerExceptionMessage:未实现方法或操作 [13] InnerExceptionStackTrace:at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType,Int16 typeId)
[14]在System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
[15]在System.Windows.Baml2006.Baml2006Reader.Process_ElementStart()
[16]在System.Windows.Baml2006.Baml2006Reader.ReadObject(KeyRecord record)上 [17]在System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
[18] System.Windows.ResourceDictionary.RealizeDeferContent(Object key,Object&amp; value,Boolean&amp; canCache)
[19]在System.Windows.ResourceDictionary.GetValueWithoutLock(Object key,Boolean&amp; canCache)
[20]在System.Windows.ResourceDictionary.GetValue(Object key,Boolean&amp; canCache)
[21]在System.Windows.ResourceDictionary.Lookup(Object key,Boolean allowDeferredResourceReference,Boolean mustReturnDeferredResourceReference)
[22]在System.Windows.StaticResourceExtension.FindResourceInEnviroment(IServiceProvider serviceProvider,Boolean allowDeferredReference,Boolean mustReturnDeferredResourceReference)
[23]在System.Windows.StaticResourceExtension.TryProvideValueInternal(IServiceProvider serviceProvider,Boolean allowDeferredReference,Boolean mustReturnDeferredResourceReference)
[24]在System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider,Boolean allowDeferredReference)
[25]在System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
[26]在MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me,IServiceProvider serviceProvider)

值得补充的是,第11行提到的MainClass是ComVisible类在系统中注册并实现了特殊的接口(比如ICOMInterface)其中:

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

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

    ...
} 

如果我不处理这个异常,那么通过实现iterface调用这个ShowSetupDialog的程序返回HRESULT 80131501,这是COR_E_SYSTEM,它是.Net中的SystemException

1 个答案:

答案 0 :(得分:0)

您应该能够深入了解异常并获取更多信息 - 请尝试发布您发现的任何内容。

如果没有这些信息,我只能假设您的Presentation2库没有对您的公共库的引用。