I'm working on upgrading an older application from .Net 2 to .Net 4. The program utilizes infopath forms, and they are causing a fair amount of annoyance to get working. First, it was throwing a FileLoadException, with the message "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 did some research and added the following to my app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
I then re-ran the application out of Visual Studio, and when it just tries to open a form, it now throws a COMException, and that "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." So I do. I added the following to my app.config file:
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
Now when it tries to open an InfoPath form, it tells me that I need to install .Net 3.5 onto my computer. I guess my question from all of this is, do I really have to install the .Net 3.5 framework onto a computer to get this application running, even though it is in .Net 4.0? The compact version of .Net 3.5 doesn't work, and I'm assuming this is all over the CAS changes from 3.5 to 4.0, but I'm hoping there's a programmatic way to rememdy this and open/save InfoPath forms without having to make the user install another Framework onto their computer.
It turns out that if you have ClickOnce security enabled(Solution Properties>Security>Enable ClickOnce Security Settings), this will cause this issue when trying to debug. However, if you publish the project (with ClickOnce security enabled) you can open up the application and use it as normal. So for debug, disable ClickOnce security, and for normal test and deployment, enable it, and then publish the project for correct use.