[英]Issues using InfoPath FormControl in VS2010
我使用 InfoPath.FormControl 在 .NET4.0 WPF 應用程序中托管 InfoPath 表單,例如
<WindowsFormsHost Name="infoPathFormsHost">
<ip:FormControl x:Name="infoPathXmlEditor"/>
</WindowsFormsHost>
一切運行良好,我可以使用以下命令成功打開 forms:
this.infoPathXmlEditor.NewFromFormTemplate(formTemplatePath, fileStream, XmlFormOpenMode.Default);
但是,當我嘗試使用 MainSource 上的 CreateNavigator 導航表單中的元素時,我開始遇到問題,例如
this.infoPathXmlEditor.XmlForm.MainDataSource.CreateNavigator().SelectSingleNode(xPathToElement);
此時我得到以下異常:
“混合模式程序集是針對運行時版本‘v2.0.50727’構建的,如果沒有額外的配置信息,則無法在 4.0 運行時中加載。”
我設法找到解決這個問題的方法是將以下內容添加到 app.config 文件中:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
但是,當我添加時,我現在在NewFromFormTemplate方法調用上得到了這個異常:
InfoPath 無法創建新的空白表單。 InfoPath 無法打開表單。 要解決此問題,請聯系您的系統管理員。
表單模板:file:/// 由於表單代碼錯誤,InfoPath 無法打開所選表單。 此方法顯式使用 CAS 策略,該策略已被 .NET 框架淘汰。 為了出於兼容性原因啟用 CAS 策略,請使用 NetFx40_LegacySecurityPolicy 配置開關。 有關詳細信息,請參閱http://go.microsoft.com/fwlink/?LinkID=155570 。
有誰知道這個問題的解決方案? 任何幫助將非常感激。
注意:InfoPath FormCode.cs 中沒有代碼隱藏。
添加
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<startup/>
<runtime>
<netFx40_LegacySecurityPolicy enabled="true"/>
<runtime/>
添加運行時標簽后它對我有用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.