在 VS2010 中使用 InfoPath FormControl 的问题
我使用 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 无法打开该表单。要解决此问题,请联系您的系统管理员。
表单模板:文件:/// 由于表单代码中有错误,InfoPath 无法打开所选表单。 此方法显式使用 CAS 策略,该策略已被 .NET Framework 废弃。为了出于兼容性原因启用 CAS 策略,请使用 NetFx40_LegacySecurityPolicy 配置开关。请参阅http://go.microsoft.com/fwlink/?LinkID=155570了解更多信息。
有谁知道这个问题的解决方案?任何帮助将不胜感激。
注意:InfoPath FormCode.cs 中没有代码隐藏。
I am hosting an InfoPath form in a .NET4.0 WPF application using a InfoPath.FormControl
e.g.
<WindowsFormsHost Name="infoPathFormsHost">
<ip:FormControl x:Name="infoPathXmlEditor"/>
</WindowsFormsHost>
Everything runs fine and I can successfully open forms using:
this.infoPathXmlEditor.NewFromFormTemplate(formTemplatePath, fileStream, XmlFormOpenMode.Default);
However I start running into problems when I try and navigate elements in the form using CreateNavigator on the MainSource, e.g.
this.infoPathXmlEditor.XmlForm.MainDataSource.CreateNavigator().SelectSingleNode(xPathToElement);
at which point I get the following exception:
"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."
I managed to find out the way to overcome this is to add the following to the app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
However when I add that I now get this exception on the NewFromFormTemplate method call:
InfoPath cannot create a new, blank form.
InfoPath cannot open the form. To fix this problem, contact your system administrator.
Form template: file:///
InfoPath cannot open the selected form because of an error in the form's code.
This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.
Does anyone know the solution to this problem? any help would be much appreciated.
Note: there is no code-behind in the InfoPath FormCode.cs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加 添加
运行时标签后它对我有用!
Add
It worked for me after adding the runtime tag!