Windows Installer from .Net 2.0 Custom Action to .Net 4.0 Custom Action - BadImageFormatException - .net-4.0

I'm having a problem with an application that I recently upgraded from .Net 2.0 to .Net 4.0. During installation, the custom action starts to execute and throws an error.
=== Logging started: 9/30/2011 2:34:09 ===
Error 1001. Error 1001. Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\MyPath\MyCustomAction.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded..
=== Logging stopped: 9/30/2011 2:34:30 ===
Note that should I uninstall the old version of the application first, then install the new version of the application, the installation succeeds without error.
The only thing I can guess is that the .Net 2.0 custom action is failing to be loaded by Windows Installer as it's not the same .Net 4.0 framework as used by the latest version of my application. Has anyone run into this?

You've got to set the condition for the runtime in the vdproj (it doesn't update with your custom action project):
http://msdn.microsoft.com/en-us/library/kz0ke5xt.aspx
In Solution Explorer, click the Setup project.
On the View menu, point to Editor, and then click Launch Conditions.
Click .NET Framework.
In the Properties window, change the Version property to the version of the .NET Framework that you want the Setup project to check for and install.

Related

VB.NET application compiled to target 4.6.1 framework does't run successfully on Computer with only 4.8 .Net framewor

I intend to build simple Winform application just to allow user to automate their file creation and store the last filled form in a file to keep it for next run.
thus, I'm not interested in creating installer for this simple Winform application. I expected to only compile it to .exe and let it run on other computers.
I develop the application using VS2019 community with target .net 4.6.1
It won't run on computer with Windows 10 with only .net framework 4.8
We are not able to install framework 4.6.1 since it says an earlier version of .net framework is already installed.
Should I recompile my application with target .net framework 4.8?
Can't I compile my application to run on any computer which at least has 4.6.1 or newer? without installer.
(I don't really understand the .net framework backward compatibility truly mean)
my application uses:
library of user32.dll for SetForegroundWindow function
to create .ini file
Finally it works. Even compiled to target .NET 4.6.1 still work on .NET 4.8 computer actually.
The issue is because my application is targeting to another application using interope COM interface, while the license is not sufficient for the user to allow COM interface.
we notice it when we finally create a pure simple windows form, then step-by-step compiling while adding each feature.
Sorry Every Body for this silly case. And my special apologize to evry1falls for spending your time.
I'm thinking to change this Question or delete it. because it is not the issue at all
The Actual Issue is:
I created Windows Form Application starting from a blank Project. And I don't know that the .NET Unhandled Exception is not activated by default.
When created from Windows Form Project Template, the Unhandled Exception message shown.
I created another Question about it: Here

Custom action calling into .NET 4 assembly

I have a .NET library (dll) of helper methods specific to installing my product, that targets .NET 4.
However, the "main" WIX project is targeting .NET 3.5 (as specified in the documentation) (meaning it runs on the 2.0 runtime). It has custom actions that call into the above 4.0 dll.
When running the generated MSI, i get "BadImageFormat" exceptions, when the WIX runtime (running on 2.0 runtime) tries to load my 4.0 dll.
If I had direct access to a .NET 3.5 .exe, I could convince it to load a 4.0 dll by using the trick in its app.config.
However, the WIX runtime is loaded (by msiexec), as far as I can tell from the stack trace, through Interop.
Does anybody have a suggestion on how I could get this to run?
PS. I also tried making the "main" Wix project target 4.0 directly instead of 3.5, but then my setup dialogs will just fail to show.
I don't know how you have this setup in wixsharp, but in Visual Studio WiX has a project template for C#/DTF custom actions. It automatically includes a CustomAction.config that you can use to put SupportedRuntime elements in to achieve what you are trying to do.
Take a look at WIX and Custom Actions
The BadImageFormat exception means that you are attempting a cross architecture call somewhere in your calling sequence, 32-bit to 64-bit or vice versa. That might be a consequence of getting the incorrect framework, but not necessarily!

New ASP.NET 5 preview project fails to run

I created a new ASP.NET 5 preview project in VS 2015 RTM (fully updated). When I try to debug it, it fails with the following exception:
The current runtime target framework is not compatible with
'ProjectName'.
Current runtime Target Framework: 'DNX,Version=v4.5 (dnx45)' Type:
CLR Architecture: x86 Version: 1.0.0-beta6-12256
Please make sure the runtime matches a framework specified in
project.json
I went with the default settings in the new project dialog, which I believe included a dependency on .NET 4.5.1 (though there's no mention of that dependency in the project.json file - contrary to what the exception message claims). I tried the solution offered here (defining the DNX_IIS_RUNTIME_FRAMEWORK environment variable in the project's debug settings) without success.
Install latest tools and try again. Beta 6 isn't apt to be supported and lots changed since then. You can get the tools here: http://www.microsoft.com/en-us/download/details.aspx?id=49442

Why won't my vb.net project recognize its framework?

So I've been working on the same windows form application for a while now. Recently I added a form that uses crystal reports and a crystal reports viewer. Since the addition any attempt at deployment has been unsuccessful.
When I installed crystal reports, I needed to change the framework of my project from 4.0 client to 4.0. On building my solution I received the following error message:
WARNING: The version of the .NET Framework launch condition '.NET Framework 4' does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box.
Following the message I went to the launch conditions page for my solutions and changed the framework version, but after running another build, the error persists along with a new error:
An error occurred while validating. HRESULT = '8000000A'
I'm using VS2010 and I found through other posts that this was known error and was seemingly irreparable. Does anyone have any suggestions?
Right click on your setup project and choose View->Launch Conditions. Under Launch Conditions click on .Net Framework. Under the properties section, the Version can be clicked on to change it to ".Net Framework 4" from ".Net Framework 4 Client Profile".

wix sfxca binding to CLR v 2.0 instead of v4.0

Iam building managed custom actions using .net 4.0, but when i package the installer and run it,it fails giving me "assembly is built by newer version" error.
In the install log I can also see that the SfxCA is binding to v2.0 instead of 4.0, how can i configure it so it loads the v 4.0 version
many thanks
Check if this thread is helpful.