我有两个类库包含使用窗口和用户控件一些演示的一部分。假设它是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
Presentation2对公共库有参考。我已经为这个问题^ _ ^提供了更多的信息 – PompolutZ 2011-06-08 11:06:37