locked
How to load 4.0 assembly from a 3.5 assembly using reflections RRS feed

  • Question

  • Hi,

    I have a Visual Studio 2010 solution with 3 projects running .NET 3.5 and one running .NET 4.0.

    Now, in one of the 3.5 projects, I need to use reflection to load and execute methods in the 4.0 assembly. When I debug I get an exception trying to load, and I assume this is because the 4.0 assembly is not installed in the GAC... at least not in the "normal" GAC (c:\windows\assembly). After google'ing a bit I found that if you use a 4.0 versjon of GacUtil to install 4.0 assemblies, they end up in c:\windows\microsoft.net\assembly.

    Any ideas?

    Thanks!

    Friday, February 3, 2012 7:09 AM

Answers

  • Hi Relapse666,

    Welcome to the MSDN forum.

    I think you can try Assmebly.LoadFrom method:

                    Assmebly.LoadFrom method

    It will load an assembly given its file name or path. And .Net framework 4.0 assemblies are in the following directory by default:

                    C:\Windows\Microsoft.NET\Framework\v4.0.30319

    And please feel free to let me know if I misunderstood anything.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Lie You Monday, February 6, 2012 9:57 AM
    • Marked as answer by Lie You Friday, February 10, 2012 1:11 AM
    Monday, February 6, 2012 9:57 AM

All replies

  • Hi Replapse666,

     

      You can load lower version assembly through set config file.

    <configuration>

    <startup>

    <supportRuntime version="4.0.20506"/>

    </startup>

    </configuration>

     

    Sincerely,

    Jason Wang


    orichisonic http://blog.csdn.net/orichisonic
    Friday, February 3, 2012 8:52 AM
  • Hi,

    Thanks for your reply.

    I'm not real sure how to do this in this case though, because the project that needs to load the 4.0 assembly through reflections is just Class Library project.

    Please advise.

    Thanks!

    Friday, February 3, 2012 11:05 AM
  • Hi Relapse666,

    Welcome to the MSDN forum.

    I think you can try Assmebly.LoadFrom method:

                    Assmebly.LoadFrom method

    It will load an assembly given its file name or path. And .Net framework 4.0 assemblies are in the following directory by default:

                    C:\Windows\Microsoft.NET\Framework\v4.0.30319

    And please feel free to let me know if I misunderstood anything.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Lie You Monday, February 6, 2012 9:57 AM
    • Marked as answer by Lie You Friday, February 10, 2012 1:11 AM
    Monday, February 6, 2012 9:57 AM