C# XAML 解析异常 - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9045378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XAML Parse Exception - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
提问by Luke
I was working on a WPF project on my PC last night, using VS 2010 Ultimate.
昨晚我在我的 PC 上使用 VS 2010 Ultimate 处理 WPF 项目。
I have just opened it up on my Netbook with VS C# 2010 Express.
我刚刚用 VS C# 2010 Express 在我的上网本上打开了它。
When I try to run it, it I am thrown an XAML Parse Exception which tells me that the line:
当我尝试运行它时,它会抛出一个 XAML 解析异常,它告诉我该行:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Is the problem. I can't see a problem with it, I have never changed it and it looks like it is what it should be.
是问题。我看不出它有什么问题,我从来没有改变过它,看起来它应该是这样。
The Error:
错误:
'The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
Full XAML:
完整的 XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Camera" Height="550" Width="826" Background="#ddd" ResizeMode="NoResize" WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown" BorderBrush="#FF8D8D8D" BorderThickness="2" >
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Width="830" Height="510">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="132" />
<ColumnDefinition Width="698*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="29" />
<RowDefinition Height="319" />
<RowDefinition Height="121" />
<RowDefinition Height="16" />
<RowDefinition Height="25*" />
</Grid.RowDefinitions>
<ComboBox Name="PortNames" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" SelectionChanged="PortNames_SelectionChanged" Margin="12,6,0,0" />
<Ellipse Grid.Row="2" Height="120" HorizontalAlignment="Left" Name="ellipse1" StrokeThickness="6" VerticalAlignment="Top" Width="120" MouseLeftButtonDown="ellipse1_MouseLeftButtonDown" Margin="12,0,0,0">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#89FF0000" Offset="0" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush>
</Ellipse.Fill>
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#FFB10000" Offset="0" />
<GradientStop Color="#83B20707" Offset="0" />
<GradientStop Color="#F7B00000" Offset="1" />
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<Button Content="Sync" Height="23" HorizontalAlignment="Left" Margin="57,6,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Grid.Row="1" />
<Rectangle Height="23" HorizontalAlignment="Left" Margin="12,6,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Fill="Red" Width="39" OpacityMask="#AA000000" Grid.Row="1" />
<ProgressBar Grid.Row="4" Height="19" HorizontalAlignment="Left" Name="progressBar1" VerticalAlignment="Top" Width="120" Margin="12,2,0,0" />
<Rectangle Grid.RowSpan="5" Grid.Column="1" Height="500" Name="rectangle1" Stroke="#aaa" Width="660" Fill="#eee" Margin="12,5,26,5" />
<Button Grid.Column="1" Height="18" HorizontalAlignment="Left" Margin="630,-20,0,0" Name="image1" VerticalAlignment="Top" Width="40" Click="image1_Click"><Image Stretch="Fill" Source="/PhotoProgram;component/Images/Close.png" /></Button>
<Button Grid.Column="1" Height="18" HorizontalAlignment="Left" Margin="587,-20,0,0" Name="minimize" VerticalAlignment="Top" Width="40" Click="minimize_Click"><Image Stretch="Fill" Source="/PhotoProgram;component/Images/Minimize.png" /></Button>
</Grid>
采纳答案by ose
XAMLParseException is a common exception thrown in WPF. Unfortunately it isn't very helpful.
XAMLParseException 是 WPF 中引发的常见异常。不幸的是,它不是很有帮助。
To help find out what the real error is, you can turn on exception reporting much earlier in Visual Studio. Default key combination is Ctrl + Alt + E. From there, check all the boxes.
为了帮助找出真正的错误是什么,您可以更早地在 Visual Studio 中打开异常报告。默认组合键是 Ctrl + Alt + E。从那里,选中所有框。
Now the exception that is thrown in your code will be highlighted in the debugger.
现在,在您的代码中抛出的异常将在调试器中突出显示。
回答by Hashmat Khalil
that xaml looks ok. there shouldnt be any problem with that. i think you try to get some data. are you trying get some message with your application? if so the default message size is 65536 bytes. increase that number in your app.config. also open the output windows while running you program and check if there are binding errors.
那个 xaml 看起来不错。应该没有任何问题。我认为您尝试获取一些数据。您是否正在尝试通过您的应用程序获取一些消息?如果是这样,默认消息大小为 65536 字节。在您的 app.config 中增加该数字。还可以在运行程序时打开输出窗口并检查是否存在绑定错误。
回答by Abhishek Malick
Try this one from reference
试试这个参考
"Ur needed dll"->properties->copy to local->true (change it from false)
“您需要的 dll”-> 属性-> 复制到本地-> 真(将其从假更改)
save & clean solution & then rebuild it. I think it will work(worked for me).
保存并清理解决方案,然后重建它。我认为它会起作用(对我有用)。
回答by Bassie
I had this error and changing exception reporting did not seem to help
我遇到了这个错误,更改异常报告似乎没有帮助
I noticed that I was trying to call:
我注意到我试图打电话:
var processClass = new ManagementClass(@"\server.domain1.co.uk\root\cimv2:Win32_Process");
Where \servershould be \\server
\server应该在哪里\\server
Changing this fixed the issue but it is pretty annoying having an error message that doesn't tell you anything about your error.
更改此设置解决了问题,但出现错误消息却没有告诉您有关错误的任何信息非常烦人。
I have actually noticed this error in a few places when a string has not been properly formed in wpf, so that could be a good place to start.
当 wpf 中的字符串没有正确形成时,我实际上在几个地方注意到了这个错误,所以这可能是一个很好的起点。

