【问题标题】:Issues using InfoPath FormControl in VS2010在 VS2010 中使用 InfoPath FormControl 的问题
【发布时间】:2011-06-29 06:47:51
【问题描述】:

我正在使用 InfoPath.FormControl 在 .NET4.0 WPF 应用程序中托管 InfoPath 表单 例如

<WindowsFormsHost Name="infoPathFormsHost">
    <ip:FormControl x:Name="infoPathXmlEditor"/>
</WindowsFormsHost>

一切正常,我可以使用以下方法成功打开表单:

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 无法打开所选表单。 此方法显式使用已被 .NET Framework 废弃的 CAS 策略。为了出于兼容性原因启用 CAS 策略,请使用 NetFx40_LegacySecurityPolicy 配置开关。请参阅http://go.microsoft.com/fwlink/?LinkID=155570 了解更多信息。

有人知道这个问题的解决方法吗?任何帮助将不胜感激。

注意:InfoPath FormCode.cs 中没有代码隐藏。

【问题讨论】:

    标签: visual-studio-2010 .net-4.0 infopath-2007


    【解决方案1】:

    添加

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319"/>
    <startup/>
    <runtime>
    <netFx40_LegacySecurityPolicy enabled="true"/>
    <runtime/>
    

    添加运行时标签后它对我有用!

    【讨论】:

      猜你喜欢
      • 2011-06-27
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多