1

As you know , we can run executable .net application on different .net CLR versions using application config file ( for example MyProject.exe.config ) by following content :

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
      </startup>
</configuration>

i search for this trick to use it on .Net DLL files but nothing found , i test it using config file like MyDLL.dll.config , at the begining i think CLR do not use my dll config file ( my DLL builded using .Net framework 2 and on my VM i have just .Net Framework 4 ) when i run my native application that use .Net DLL , it throw the exception : Can't find CLR version or something like this .

in my test process i see a strange encounter , if my DLL build using .Net Framework 4 and run it on VM's windows , it run properly ( VM's windows has .Net 4 and it's normal behavior ) , but if i put a config file inside my DLL ( MyDLL.dll.config ) and put the following content in it , it can't run and throw same exception as .Net Framework 2 , it meanse the CLR can see the dll's config file and use it !

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v2.0.50727"/>
      </startup>
</configuration>

What's your idea about this problem ? why .Net 4 can not run my .Net 2 DLL but it can run application (exe file) by same config properly ?

Sorry for my bad English .

Mojtaba Tajik
  • 1,725
  • 16
  • 34
  • 1
    The use of config files for .dll's is not supported by the .net runtime and is usually ignored. In any case it would not invoke the 2.0 runtime as only nor can be present at a time, code is forward compatible meaning that .net 2.0 code will run on a system with .net 4.0 installed but code built with 4.0 will not run on a .net 2.0 system. I would take the supported version statements out of your main .config file as well – Mike Beeler Nov 18 '13 at 04:12
  • @MikeBeeler i say that i want to run my .Net 2 DLL on .Net 4 but it fails and the config file dose not solve the problem , i know that the config file is unusable on DLL files but compile a DLL using .Net 4 and put a config file inside DLL and add to it when try to run DLL in windows that have been installed .Net 4 , DLL fails to start , the config file should not apply any behavior to CLR because it's DLL file not exe file , ok ? but it fails to run! it means the config file apply on dll file and change the behavior of .Net CLR! Why ?! – Mojtaba Tajik Nov 18 '13 at 05:53
  • First look at this link http://stackoverflow.com/questions/594298/c-sharp-dll-config-file what specific failure do you get when you try to run your lent 2.0 dll and how exactly are you running it? – Mike Beeler Nov 18 '13 at 06:02
  • the exception is : "unable to find a version of the runtime to run this application" i run it using native application . – Mojtaba Tajik Nov 18 '13 at 06:22
  • Depending on the age of the computer .net 2.0 may not be installed on the specific system that you are testing on, if that's the case you need to download and install the 2.0 runtime which you can download from Microsoft. Is there some reason that your dll needs to be built with 2.0 vs 4.0 – Mike Beeler Nov 18 '13 at 06:35
  • The reason is my program should run on several different systems , some of them have .Net 2 , some of them have .Net 3 or 3.5 and some of them have .Net 4 , i solve the problem for my exe files using config file but i should solve this problem for my DLLs too , it's not possible to upgrade all systems .Net frameworks . I can solve this problem if my host app was managed , but currently my host app is native . – Mojtaba Tajik Nov 18 '13 at 06:50
  • So you have a host app that is not written in .net but c or c++ and you are using interop or com to get at the managed .net dll because the way your app config is set up if the .net 4 runtime is not present use .net 2.0 – Mike Beeler Nov 18 '13 at 06:58

0 Answers0