C# 在InitializeComponent()处未处理XAMLParseException
我正在使用wpf在.NETFramework4.0中开发我的项目。 以下是crystal report viewer的XAML代码C# 在InitializeComponent()处未处理XAMLParseException,c#,wpf,crystal-reports,C#,Wpf,Crystal Reports,我正在使用wpf在.NETFramework4.0中开发我的项目。 以下是crystal report viewer的XAML代码 <Window x:Class="KhataBahi.GenerateReports" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=http://schemas.microsoft.com/winfx/2006/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
<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>
可能是因为xmlns:x中缺少引号=http://schemas.microsoft.com/winfx/2006/xaml
?我也试过了,但仍然给出了相同的异常。@Jefferson its显示了一个XAML解析异常,说明:“对与指定绑定约束匹配的类型'SAPBusinessObjects.WPF.Viewer.ViewerCore'调用构造函数时引发异常。“是否存在嵌套的InnerException?什么是ViewerCore
?请看,为什么会出现异常。InnerException声明:“CrystalDecisions.Shared.SharedUtils”的类型初始值设定项引发了异常。我已检查了内部异常,它是一个XAML解析异常,说明:”对与指定绑定约束匹配的类型“SAPBusinessObjects.WPF.Viewer.ViewerCore”调用构造函数时引发了异常。“应该还有更多。它是否试图说它无法向其构造函数解析某些内容?InnerException状态:”“CrystalDecisions.Shared.SharedUtils”的类型初始值设定项引发了一个异常。“应该有另一个内部异常:”