2
votes

I've built a windows service code with Framework Verison 4.0, when I sent my service.exe for instllation at different machine which has version 2.0 installed it gave error:

"Exception occurred while initializing installation:

System.BadImageFormatException: couls not load file or assembly '\service.exe' or one of its dependencies. This assembly is built by a runtime newer than currently loaded runtime and cannot be loaded"

How can I build a service which is backward compatible in visual studio

3

3 Answers

2
votes

Change your target framework to 2.0, and make sure you do not use anything that's not part of 2.0 (e.g. TPL, etc), otherwise, install .NET 4 on the target machines

enter image description here

1
votes

You cannot run .NET v4.0 code in .NET v2.0 runtime. Either install .NET v4.0 on the server or convert your servive to .NET v2.0

0
votes

When you have a .net framework 4.0 installed then you can run any application which has a target framework value as 2.0 , 3.0 , 3.5 and 4.0 and when you have a .net framework 3.5 installed then you can run any application which has target framework value as 2.0 , 3.0 and 3.5 , like this it goes on. This is mandatory requirement for .net framework , so it would be better if you ask your client to install .net framework 4.0 or create a service (i hope this is windows service and not wcf service because wcf is supported only from framework version 3.0) project which targets the framework version 2.0.