I was creating a Windows service that includes a dll file. Whenever I tried to include the dll, I get following error.
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException
I checked through internet but none of them seemed to be helpful. The script couldn’t even enter into OnStart() function and I couldn’t even write any logs to check where the program is faulty. After some research, I checked the dll compiled version. I found that the dll was compiled in version .NET 2.0.50727. Then got some hint that the service was trying to find something on .NET 4 folder but the dll library was compiled in older version and need some reference. Then finally I found that by enabling v2 legacy activation policy, it could find and load the file easily. Here is what I did:
- Open Solution Explorer for the project
- Double-click and open App.config file
- There you will find a tag something like this:
- Replace it with:
There is it ready. Now your application will run like a charm. If this was the case for Windows Form application, you will directly be notified as System.IO.FileNotFoundException with a Visual Studio error stating something like
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.
And then the application should run perfectly with the above simple replacement.