我正在使用wpf在.net framework 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 dll进入.Net 4.0运行时。所以,我将以下内容添加到我的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>
但是,没有运气。请提出解决方案。
答案 0 :(得分:0)
" "
的命名空间中没有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>