Using CustomConverters specified in other assembly throws an exception
I have two Class Libraries which contains some Presentation part using windows and user controls. Let's say that it is Presentation1 and Presentation2. I have one more CL which is Common, and both Presentation libraries referenced to it. In Common library I've specified a number of custom converters. I use them in both Presentations but in Presentation1 everything works fine, but in Presentation2 the same converters visible during design time but during runtime I receive an exception:
'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '55' and line position '35'.
If I move any of these converters to the Presentation2 and reference them from itself then they will work.
Any suggestions please what could be wrong? Thanks in advance.
Update:
My 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 looks identically, but work fine. Presentation2 throws an excpetion on that line where Converter referenced from StaticResources.
Also it worth to notice that when I moved this IntToStringConverter into my Presentation2 library (and it starts working properly as in Presentation1) incide its code I use a number of classes referenced from the same Common assembly and it also works.
Update2:
I've tried to handle this exception using DebugView and result provided below:
[1] Exception message: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '48' and line position '35'.
[2] Exception help link: [3] Exception Source: PresentationFramework [4] Exception StackTrace: at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) [5] at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) [6] at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) [7] at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) [8] at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) [9] at SettingsView.InitializeComponent() in ..\Presentation2\Presentation\presentation\SettingsView.xaml:line 1 [10] at SettingsView..ctor(TobiiEyeTrackingSettingsViewModel viewModel) in ..\Presentation\SettingsView.xaml.cs:line 14 [11] at Presentation2.MainClass.ShowSetupDialog(Object varHwndParent) in ..\Presentation2\MainClass.cs:line 171 [12] InnerExceptionMessage: The method or operation is not implemented. [13] InnerExceptionStackTrace: at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 ty开发者_如何学CpeId) [14] at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId) [15] at System.Windows.Baml2006.Baml2006Reader.Process_ElementStart() [16] at System.Windows.Baml2006.Baml2006Reader.ReadObject(KeyRecord record) [17] at System.Windows.ResourceDictionary.CreateObject(KeyRecord key) [18] at System.Windows.ResourceDictionary.RealizeDeferContent(Object key, Object& value, Boolean& canCache) [19] at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache) [20] at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache) [21] at System.Windows.ResourceDictionary.Lookup(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference) [22] at System.Windows.StaticResourceExtension.FindResourceInEnviroment(IServiceProvider serviceProvider, Boolean allowDeferredReference, Boolean mustReturnDeferredResourceReference) [23] at System.Windows.StaticResourceExtension.TryProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference, Boolean mustReturnDeferredResourceReference) [24] at System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference) [25] at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider) [26] at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)It worth to add that MainClass mentioned on line 11 is ComVisible class registred in system and implemented special interface (lets say ICOMInterface) where:
[Guid("... guid here ...")]
[ComVisible(true)]
public class MainClass : ICOMInterface
{
...
public void ShowSetupDialog(object varHwndParent)
{
SettingsView view = new SettingsView();
view.ShowDialog();
}
...
}
If I won't handle this exception then program which call this ShowSetupDialog via implemented iterface return HRESULT 80131501 which is COR_E_SYSTEM which is a SystemException in .Net
You should be able to drill into the exception and get more information - please try and post whatever you find.
In the absence of that information, I can only assume that your Presentation2 library does not have a reference to your common library.
精彩评论