Can we use .Net 4.0 framework in the Visual Basic Interop form? - vb.net

I'm having a project which is to add new features to a VB6 application. In order to migrate the application to the more advanced technology incrementally, we choose to use VB Interop technology. However, we found that the VB Interop Form is actually based on .Net 2.0. So, I'm asking how can we use higher version of the .Net framework?
thanks

Short answer is no, but stable in 3.5 framework. Microsoft is aware of the issue, but can't tell you when there would be a fix. You can find more here.
Another good read here.

Interop Forms Toolkit can be used with .NET 4.0. I have been using it for more than 6 months with no problems.
The problem discussed here is due to In-Process Side-by-Side Execution, introduced in .NET 4. With this you can have different versions of the CLR running in your application. This can be fixed by using an app.config file:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
I answered a similar problem here, and here

Related

Configure Application to run on .NET 2.0 and 4.5

I am using Visual Basic Express 2010 and are trying to configure my application to run on a large variety of computers without the need of updating .NET Framework.
My current project has the following settings in app.config:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
The target framework is .NET 2.0. One may think that, with these settings, the program should run out of the box on machines with both .NET 2.0 and 4.X
However, when I attempt to run the software on a fresh Windows 8.1 virtual machine, I run into the following error:
I'd rather not have my users install .NET 3.5 if it's not necessary. Is there a way to get past this?
Thank you all in advanced.

WIX CustomAction loading CLR 4.0 instead of 2.0

I'm trying to write a c# custom action and using .Net 2, however I can't seem to get things to work. I believe the MSI is using the wrong CLR version. I see this in the log file a few lines above where the MSI is calling my CA (line line does not appear if I comment out my CA):
SFXCA: Binding to CLR version v4.0.30319.
My custom action does not appears to load (assuming since I do not see any of the logging messages). I am using Wiz 3.6.3014.0. Is this supported or does the Windows Installer just use the latest runtime available on the machine?
Thanks
When you use WiX to create a C# custom action project, it by default creates an XML file called CustomAction.config. The purpose of this file is to instruct sfxca.dll what version of the CLR to use when running your code. The default implementation of this file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, #useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>
Basically it's a good practice for CA's written in .NET 2.0/3.0/3.5 ( all CLR 2.0 ) to be allowed to run against 4.0 because you could come across a machine that has only 4.0 installed. Generally your code should work against 4.0 and if it doesn't, I'd fix that.
Alternatively you could update the config file to only allow running on 2.0 and then put the needed checks into the installer to make sure that this version of the CLR is infact installed.

Application built with .NET 3.5 running on machine with only .NET 4.0. How does supportedRuntime element work?

We have an application that was built using .NET 3.5. There is a situation where it will run on a machine which only has .NET 4.0 installed.
If in the application configuration file the <supportedRuntime> element is not defined, or is defined as follows
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
will the application crash on start up since .NET 3.5 and CLR v2.0.50727 are not present?
Note I understand that .NET 4.0 APIs are supposed to be compatible with .NET 3.5 ones and that a .NET 3.5 application should run in .NET 4.0. That is not the question. I am specifically asking about the <supportedRuntime> behavior.
Adding Hans Passant's comment as it seems a suitable answer.
The application will crash. To run on .NET 4.0 you need to add another supportedRuntime attribute with version="4.0".

Autocad 2010 and Framework 4.0

How can i assembly "NET Framework 4" with autocad 2010.
I have problems while using NETLOAD command.
You need to use .NET 3.5 with AutoCAD 2010. 4.0 is only supported by AutoCAD 2012.
AutoCAD 2010 can support non beta .Net 4.0 versions. If you edit the acad.exe.config file you may add this to get .Net 4.0 functionality:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
You can see for yourself in this AU material:
Using .NET 4.0 with AutoCAD
If you go into the AutoCAD install folder and edit the acad.exe.config file there you can add .NET 4.0 as a supported runtime:
<startup>
<!-- v Add this line v -->
<supportedRuntime version="v4.0"/>
</startup>
Note that advanced features of C# added in 4.0 wont work because they require all assemblies involved to be compiled for that version.
Go To Project>yourappname properties>Compile>Advanced Compile options. And choose target .NET Framework 3.5

How can I target .Net 4.0 Beta using NAnt?

I want to start testing my project using the Microsoft .Net 4.0 Beta version that has already been released. I know that adding a "net-4.0" target framework to NAnt requires updating nant.exe.config file, does anyone know what are the necessary changes?
If you want to use nant to build projects targeting .NET 4.0 you'll have to modify NAnt.exe.config and add the net-4.0 target framework and add a <supportedRuntime ... /> line to the <startup> section.
http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html is a full code for .config file for NAnt.