Reputation: 11
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.
Upvotes: 1
Views: 738
Reputation: 11
Add
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<startup/>
<runtime>
<netFx40_LegacySecurityPolicy enabled="true"/>
<runtime/>
It worked for me after adding the runtime tag!
Upvotes: 1