WPF XAML references not resolved via myAssembly.GetReferencedAssemblies()
Posted
by
WPF-it
on Stack Overflow
See other posts from Stack Overflow
or by WPF-it
Published on 2012-10-15T09:19:36Z
Indexed on
2012/10/15
9:37 UTC
Read the original article
Hit count: 343
I have a WPF container application (with ContentControl
host) and a containee application (UserControl
). Both are oblivious of each other.
Only one XML config file holds the string dllpath
of the containee's DLL and full namespace name of the ViewModelClass
inside the containee.
A generic code in container resolves containee's assembly (Assembly.LoadFrom(dllpath)
) and creates the viewmodel's instance using Activator.CreateInstance(vmType)
. when this viewmodel
is hosted inside the ContentControl
of the container, and relevant vierwmodel specific ResourceDictionary is added to ContentControl.Resources.MergedDictionaries
of the content control of container, so the view loads fine.
Now my containee has to host the WPF DataGrid
using assembly reference of WPFToolkit.dll
from my local C:\Lib
folder.
The Copy Local reference to the WPFToolkit.dll
is added to the .csproj
file of the containee's project and its only referred in the UserControl.XAML
using its XAML namepsace. This way my bin\debug
folder in my containee application, gets the WPFToolkit.dll
copied.
XAML:
xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
<Controls:DataGrid ItemsSource="{Binding AssetList}" ... />
Issue:
The moment the ViewModel
(i.e. the containee's usercontrol) tries to load itself I get this error.
"Cannot find type 'Microsoft.Windows.Controls.DataGrid'. The assembly used when compiling might be different than that used when loading and the type is missing."
Hence I tried to load the referenced assemblies of the containee's assembly (myAssembly.GetReferencedAssemblies()
) before the viewmodel is hosted. But WPFToolkit
isnt there in that list of assemblies!
Strange thing is I have another dll referred called Logger.dll
in the containee codebase but this one is implemented using C# code behind. So I get its reference correctly resolved in myAssembly.GetReferencedAssemblies()
.
So does that mean BAML references of assemblies are never resolvable by GetReferencedAssemblies
?
© Stack Overflow or respective owner