在InitializeComponent()处未处理XAMLParseException
本文关键字:未处理 XAMLParseException InitializeComponent | 更新日期: 2023-09-27 18:26:41
我正在使用wpf在.net框架4.0中开发我的项目。以下是水晶报表查看器的XAML代码。
<Window x:Class="KhataBahi.GenerateReports"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
Title="GenerateReports" Height="600" Width="550">
<Grid Margin="0,0,2,-1">
<Button x:Name="Back" Content="Back" HorizontalAlignment="Left" Height="38" Margin="198,522,0,0" VerticalAlignment="Top" Width="115" Click="Back_Click"/>
<my:CrystalReportsViewer x:Name="KhataBahiAMReportsViewer" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="490"/>
</Grid>
然而,它在InitializeComponent()处给出了以下异常;
在寻找这个问题的解决方案时,有人建议发生这种情况是因为你必须明确地告诉编译器在.Net 4.0运行时中支持旧的.Net dll。因此,我在app.config文件中添加了以下内容
<startup useLegacyV2RuntimeActivationPolicy="true" >
<supportedRuntime version= "v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
但是编译器总是显示这样的消息
因此,我进一步查看了dotnetconfig40.xsd的属性,并将启动编辑为
<xs:element name="startup" vs:help="configuration/startup">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="requiredRuntime" vs:help="configuration/startup/requiredRuntime">
<xs:complexType>
<xs:attribute name="version" type="xs:string" use="optional" />
<xs:attribute name="safemode" type="xs:boolean" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="supportedRuntime" minOccurs="1" maxOccurs="unbounded" vs:help="configuration/startup/supportedRuntime">
<xs:complexType>
<xs:attribute name="version" type="xs:string" use="optional" />
<xs:attribute name="sku" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="useLegacyV2RuntimeActivationPolicy" type="xs:boolean" use="optional" />
<!-- see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx -->
</xs:complexType>
</xs:element>
这删除了警告,但异常一直持续到。我甚至尝试在app.config 中显式绑定程序集
<runtime>
<assemblyBinding xmlns ="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer">
<probing privatePath="C:'Program Files (x86)'SAP BusinessObjects'Crystal Reports for .NET Framework 4.0'Common'SAP BusinessObjects Enterprise XI 4.0'win32_x86"/>
</assemblyBinding>
</runtime>
但是,没有运气。请提出解决方案。
x
的命名空间中没有" "
。此外,检查内部异常
<Window x:Class="KhataBahi.GenerateReports"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
Title="GenerateReports" Height="600" Width="550">
<Grid Margin="0,0,2,-1">
<Button x:Name="Back" Content="Back" HorizontalAlignment="Left" Height="38" Margin="198,522,0,0" VerticalAlignment="Top" Width="115" Click="Back_Click"/>
<my:CrystalReportsViewer x:Name="KhataBahiAMReportsViewer" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="490"/>
</Grid>
</Window>