Unable to load WPF toolkit.

Oct 13, 2008 at 2:13 AM
I am getting the following errors when attempting to lunch a sample application.  Any suggestions?

System.Windows.Markup.XamlParseException occurred
  Message=" 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.  Error at object 'System.Windows.Controls.Grid' in markup file 'EMS.ControlsLibrary;component/wpf/logview.xaml' Line 249 Position 14."
  Source="PresentationFramework"
  LineNumber=249
  LinePosition=14
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
       at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
       at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
       at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
       at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
       at System.Windows.Markup.TreeBuilder.Parse()
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at ControlsLibrary.wpf.LogView.InitializeComponent() in c:\repo\OCC600\Source\Libraries\ControlsLibrary\wpf\LogView.xaml:line 1
       at ControlsLibrary.wpf.LogView..ctor() in C:\repo\OCC600\Source\Libraries\ControlsLibrary\wpf\LogView.xaml.cs:line 28
  InnerException: System.ApplicationException
       Message="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."
       Source="PresentationFramework"
       StackTrace:
            at System.Windows.Markup.BamlMapTable.ThrowException(String id, String parameter)
            at System.Windows.Markup.BamlMapTable.GetTypeFromId(Int16 id)
            at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
            at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
            at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
            at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
       InnerException:

Jan 3, 2009 at 1:03 PM
There is some general information about this error message (not specific to the datagrid) here and here.

I fixed this by putting a reference to WPFToolkit in my main project, in addition to the module project that actually uses the DataGrid.

I don't understand why the WPFToolkit assembly in particular has this problem. We have other third-party assemblies that reside in the same location, and are used in the same module (and not directly by the application.) Those load just fine.
Jan 15, 2010 at 9:56 PM
Edited Feb 17, 2010 at 6:45 PM

Thanks--had the same problem, and your fix worked nicely. The only problem with the fix is that it binds the main project to the control. I am building a Prism app, so the main project should not contain such a reference, only the module project. So, I am still looking for a solution that does not call for a reference in the main project.

Mar 8, 2010 at 5:24 PM

This worked great for me, that is until we tried to run our application through the web (IE being the 'main project').

We had to add the following line to the main entry point of our web component (in the constructor event).

 Assembly.Load("WPFToolkit, Version=3.5.40128.1, Culture=neutral, processorArchitecture=MSIL");

Hope this helps!

Mar 8, 2010 at 6:20 PM

For the benefit of others who may be researching this issue. The app I had problems with is a Prism app, and as it turns out, I had forgotten to add a post-build event to add the WPF Toolkit DLL to the Shell project. Prism apps are structured to eliminate dependencies between a shell app and the modules that run in the shell. As a result, Visual Studio didn't pick up the WPF Toolkit as a dependency of the shell app, which means it wasn't getting copied to the solution output directory (that is, the shell project output directory). I added a post-build event in the module that uses the WPF Toolkit to copy the DLL to the shell project output directory, and that resolved the problem. Hope that helps!

Oct 4, 2010 at 3:34 PM

Thank you dcveeneman! You save me a lot of work with your post. I was in the same boat.