I get this error when running the application.
XmlParseException Occured
Could not load file or assembly 'System.Windows.Controls.DataVisualization.Toolkit, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified
XAML
<UserControl x:Class="myNamespace.Views.ChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chart="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Label Margin="10" Content="Scatter series" />
<chart:ScatterSeries DependentValueBinding="{Binding Value}"
IndependentValueBinding="{Binding Key}"
ItemsSource="{Binding PlotValues}" />
</Grid>
ViewModel:
public ObservableCollection<KeyValuePair<double, double>> PlotValues
{
get { return _plotValues; }
set { _plotValues = value; }
}
I think your problem is related to an issue/bug with the dependency detection in Visual Studio or MSBuild (related bug can be found here).
I've been able to reproduce your problem by doing the following:
Create a new WPF application
Create a new UserControl Library
Install the System.Windows.Controls.DataVisualization.Toolkit NuGet package on the UserControl Library (not the WPF application)
Add the scatter series
Add the custom user control containing the scatter series to the main window and running the application
The problem seems to be that without any reference to anything in the code (outside XAML), Visual Studio assumes that you are not using the assembly and therefore does not copy it to the output directory of the main application/project referencing it. More details can be found here, although these are references in ordinary code (C#, not XAML).
There are three workarounds which seems to make Visual Studio detect the dependency which I know of:
Give the control a name, and any name will do (my preferred solution)
Add a C# code reference to a controller in the Control Library (dummy code)
Add the NuGet or .dll reference to the actual application which is run
After having struggled with the same issue myself for a few hours, I believe to have discovered that Visual Studio is unable to detect the dependency on the dll based on a single usage directly in the XAML without a code reference (or a Name, which creates a code reference for you, allowing you to access the controller in the code-behind).
Edit:
I have reported this issue to Microsoft through Connect, so that they hopefully will fix it.
Related
I'm using VS2013 Express. I'm quite new in WPF and MVVM. I've downloaded mvvmlight using NuGet to my project. I'm tryinng to use GalaSoft_MvvmLight_Command:EventToCommand. As far as I know, I have to add reference in xaml by adding namespace:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight"
But, unfortunatelly I get error, that says:
The tag 'EventToCommand' does not exist in XML namespace
'clr-namespace:GalaSoft.MvvmLight;assembly=GalaSoft.MvvmLight'.
I've found some information, that I have to include GalaSoft.MvvmLight.WPF45 assembly, but I don't see this dll in packages\MvvmLightLibs.5.0.0.1\lib\ folder. There are many folders, for each .NET version etc, but each of these assemblies names are the same, without WPF45 sufix.What is going on? Where do I find this GalaSoft.MvvmLight.WPF45.dll assembly? Or maybe in version 5 was some changes made in names?
Edit:
Using object browser I found that EventToCommand is in GalaSoft.MvvmLight.Platform assembly in GalaSoft.MvvmLight.Command namespace. So I did
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
I can compile project now, but I still get errors in xaml (what is weird):
A value of type 'EventToCommand' cannot be added to a collection or dictionary of type 'TriggerActionCollection'
and
The type 'EventToCommand' from assembly 'GalaSoft.MvvmLight.Platform' is built with an older version of the Blend SDK, and is not supported in a Windows Presentation Framework 4 project.
and xaml editor can't display window properly (invalid markup).
Edit2:
Solution for invalid markup.
After I've changed the namespace to xmlns:cmd="http://www.galasoft.ch/mvvmlight" I also change project's target framework from 4.5 to 3.5. IDE shows an error about there are few NuGet packages that target other framework, so I returned to 4.5 - and it magically works now ;). Thanks all for help.
Here's how its done now in your XAML assuming you've got Version 4.0.0. Beat 1 or higher:
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
I found this at the bottom the release notes here: http://www.mvvmlight.net/installing/changes/
Details
XmlnsDefinitionAttribute for GalaSoft.MvvmLight.Command in Extras assembly
Thanks to the addition of XmlnsDefinitionAttribute, you can simplify the inclusion of the MVVM Light EventToCommand action in XAML. See the before and after below:
Before:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
After:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
EventToCommand exists in the Extras assembly.
Try:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
More Information:
To determine the assembly a class falls in, I usually Go To Definition and the assembly is referenced in the region at the top of the [from metadata] code file.
I'm aware this is the same issue as raised in "PageFunction is not supported in a Windows Presentation Foundation (WPF) project" 2012 - however, I'm unsure as to how to apply the workaround mentioned there, and thought it may be more appropriate to raise this as a separate question. Apologies in advance if this is against the site ethos.
To summarise the problem: I have a C# Visual Studio 2010 WPF project that's a couple of years old, which I'm now trying to open in Visual Studio 2012. Although the project still builds and runs fine, I need to edit the XAML markup, and the Design view in VS2012 complains of "Invalid Markup". The exact error it's tripping up on is:
Page Function is not supported in a Windows Presentation Foundation
(WPF) project
The start of the XAML looks like:
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace"
x:Class="MyProject.WizardPage1"
x:TypeArguments="local:WizardResult"
KeepAlive="True"
WindowTitle="My Project" Height="350" ShowsNavigationUI="False" Width="700" >
As mentioned in the original question, there are reports of this exact issue on this Microsoft page. There is a workaround mentioned involving "ViewBase", but I cannot see how this relates to the PageFunction problem (I'm very new to XAML so I may be missing something simple).
I've tried opening the project in Blend for VS2012 (the new Preview version that supports non-Windows 8 projects), but that gives the same error about PageFunction not being supported. The recent Update 1 for VS2012 hasn't fixed the problem either.
Can anyone advise what I need to change in my XAML or code-behind in order to be able to visually edit this page?
Or should I give up and just re-download VS2010 in order to edit this project?
Based on the workaround, you'll need to create a class which derives from PageFunction<WizardResult>, and then update your XAML to inherit from that class.
Class:
public class WizardResultPageFunction : PageFunction<WizardResult>
{
}
Code-behind:
Either change the class to inherit from your new class, or remove the base-class declaration completely and let the XAML define the base class:
public partial class WizardPage1
// or:
// public partial class WizardPage1 : WizardResultPageFunction
{
...
}
XAML:
Replace the PageFunction with local:WizardResultPageFunction and remove the x:TypeArguments attribute:
<local:WizardResultPageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace"
x:Class="MyProject.WizardPage1"
KeepAlive="True"
WindowTitle="My Project" Height="350" ShowsNavigationUI="False" Width="700"
>
Im trying to host Magtek card reader into WPF, so i encapsulated their demo into a Windows forms user control, when i use the dll from this control in a Windows application, it works fine, but when used in WPF it gives this error:
Could not load file or assembly 'Interop.ctlUSBHID, Version=1.3.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
My code:
xmlns:mcl="clr-namespace:CardReader;assembly=CardReader"
<WindowsFormsHost Name="wfh"
DockPanel.Dock="Top"
Height="300">
<mcl:Reader Name="_Reader"/>
</WindowsFormsHost>
Your help is much appreciated
Have you referred the assemblies,
WindowsFormsIntegration and
System.Windows.Forms
in your wpf application?
What worked for me was removing the Interop.ctlUSBHID file from project's References. This file is not supposed to be added manually in references as it will be generated automatically by ctlUSBHID.dll while code compilation.
I am receiving an error message "Recursive call to Automation Peer API is not valid" when loading a datagrid with a datatemplatecolumn containing a combobox column. The error ends up caught in our unhandled exception code. This seems to be an issue on my machine, and google has provided no source of guidance on resolving the issue. The issue appears to only occur when I am populating the comboboxes with data. Populating the comboboxes (if I do not load data) works correctly, and while the error is displayed I am able to see the data properly retrieved in the background.
I am using a WPF datagrid where I'm using a DataGridTemplateColumn for adding a combobox inside the grid. I have the drop down list bound to an enum using an objectdataprovider. In the code behind when initializing my screen I use a Linq2Sql statement to retrieve data and populate the Itemssource of the grid.
<grid:DataGrid.Resources>
<ObjectDataProvider
x:Key="ChangeTypeData"
MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="namespace:ChangeType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</grid:DataGrid.Resources>
<grid:DataGrid.Columns>
<grid:DataGridTextColumn Binding="{Binding DatapointName}" Header="Datapoint Changed" IsReadOnly="True" Width="Auto" />
<grid:DataGridTemplateColumn Header="Change Type">
<grid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
Text="{Binding Path=ChangeTypeName}"
ItemsSource="{Binding Source={StaticResource ChangeTypeData}}"
Name="dgcboChangeType"
SelectionChanged="dgcboChangeType_SelectionChanged"/>
</DataTemplate>
</grid:DataGridTemplateColumn.CellTemplate>
Any and all guidance on solving this issue is appreciated.
I've bypassed the problem on my end by turning off Automation on the grid control. I found that the problem was unique to the WPF Toolkit control, but I was having problems transitioning to the 4.0 official release DataGrid (unrelated to this question.)
So instead, I derive the class from the WPFToolkit and supply this override:
protected override AutomationPeer OnCreateAutomationPeer()
{
return null;
}
Maybe someone can tell us if this is a good idea or not.
I had exactly the same error. However for me it was strange that the same application was working fine on my laptop and caused the error on my desktop PC. The same OS, the same architecture and the same Visual Studio with the same add-ons.
So I checked references to WPFToolkit on my laptop, where everything was fine. It pointed to:
C:\Program Files (x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll
then I checked reference on my desktop, it pointed to:
C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll
As you can see I had two different versions of WPFToolkit installed. I copied whole folder from my laptop to my desktop, changed references from version v3.5.50211.1 to v3.5.40619.1 and the problem was resolved. No more exceptions. Hope this will help someone as well.
I was getting the same problem in NET 3.5 with WPFToolkit DataGrid.
I have bound my WPFToolkit DataGrid to EntityFramework ObservableCollection, with hierarchy of entities that have two way associations (Parent<->Items).
I solved the issue by disabling implicitly enabled AutoGenerateColumns on the DataGrid, and manually setting the columns.
Hope this helps.
I'm getting the same problem - are you using the datagrid from the WPFToolkit, or the one that ships with .NET 4.0. We're still using the toolkit one here.
Also, I've notice that this problem does not occur when using the app through remote desktop.
Similar problem posted here:
http://wpf.codeplex.com/workitem/14443
With a proposed solution. Haven't had a chance to try it.
I also had the same problem. So I checked also the reference to the WPFToolkit. I had two same versions of WPFToolkit installed (Version v3.5.50211.1), but only on my Laptop works it fine.
So I put the older version v3.5.40619.1 on my Windows Embedded Standard 7 PC and no more exceptions.
So I came to the conclusion that in some cases the newer Version has some problems with the runing system.
Hi I also had same problem when I am running Microsoft Test Manager with our WPF application. We were using the WPFtoolkit version v3.5.50211.1, replacing WPF toolkit with lower version v3.5.40619.1 has solved this problem.
Now we are able to run the MTM tool and WPF application both simultaneously.
In WPFToolkit v3.5.50211.1 one bug is fixed related to UI Automation and I guess because of that this automation peer issue is coming while using the latest WPFtoolkit.
I was able to fix this issue by replacing both the DataGrid and the ComboBox in the WPF XAML file with the following two derived classes which both override the OnCreateAutomationPeer() method.
public class SafeDataGrid : DataGrid
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return null;
}
}
public class SafeComboBox : ComboBox
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return null;
}
}
I had this same problem crop up on an older solution (although it was working fine on my local dev computer, but failing on the test system (with WPFToolkit 3.5.50211.1)
Turned out my local dev computer had an older WPFToolkit: 3.5.40128.1
However I did a little more checking around and realised that the problem was only when the DataGrid was a Microsoft.Windows.Controls.DataGrid (ie a WPFToolkit one), and it contained a control from the System.Windows.Controls namespace (in this case a ComboBox) - and from the .Net PresentationFramework.dll )
We'd updated the solution to .Net 4.7.1 from .Net 4.5.1 -> which would have meant a new version of the PresentationFramework.dll, but the WPFToolkit dll had not changed.
Decided that the best way to fix this was to just remove the WPFToolkit.dll reference, and update all the DataGrids from Microsoft.Windows.Controls.DataGrid to the newer System.Windows.Controls.Datagrid.
I am using a base Window class in a WPF project. In the code behind C# file the assembly to the base type is referenced and fine. In the XAML is looks like this:
<MyNamespace:WindowBase x:Class="MyNamespace.Applications.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNamespace="clr-namespace:MyNamespace.Somewhere;assembly=MyNamespace.Common"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
The solution compiles fine and I can run it. I just can't use the designer in VS 2010. It throws the following exception: The type'MyNameSpace:WindowBase' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well. they have been. I can't understand what this issue is. This particular base class is used in other projects just fine. I grabbed it for a new project and I can't use the designer. Very frustrating.
Found this problem just recently (this answer upgraded from a comment).
If you copy the dll from a network path, you must right click on the file in Windows Explorer, select Properties, then 'unblock'; there is a hidden NTFS stream associated with the file, and many files when you download from the 'net or copy from a network path, for security reasons.
Only the designer complains, yet the project builds and runs fine: weird isn't it?!
Whenever the designer is acting up against me - the first thing I do is clear the obj-folders in the project and rebuild. Sometimes they seem to go out of sync for some reason (usually when I'm drag-dropping a lot of files and renaming visual items).
I dont't know if its the same issue but in VS2008 I tried to make abstract UserControls but had to change this because the designer didnt't support any abstract base classes (however the solution was compilable and also worked as excpected).
Fixed. The library that contained my base class resided on a drive on the network that I did not have permissions to. That seemed to have no affect on VS 2008 as it worked, but VS 2010 apparently took exception to that when the designer tried to load it. Weird.