0

The title is self-explanatory of what I want to accomplish. I have a COM-visible component built in 3.5 and my new projects are 4.0. Code very similar to the one below is what I want to run from the 3.5 component.

        Assembly a = Assembly.LoadFrom(@"C:\MyCLR4.exe");
        Type t = a.GetType("MyCLR4Class");
        object o = Activator.CreateInstance(t);

Ultimately I'm getting the error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
I'm pretty discouraged by what I've found elsewhere. All I need is a workaround to accomplish this. Thanks!

Michel Triana
  • 2,486
  • 1
  • 22
  • 31
  • I don't think you can load a CLR4 assembly in CLR2 (which is what you're trying to do...). The error message is pretty clear about that. – Mark Sep 30 '10 at 16:11
  • I could understand that if I had a direct reference, since the Executing Assembly only knows about its own CLR. At runtime and late binding with reflection I don't get it. Both CLRs are installed on the machine, and each DLL knows where to initiate itself and their corresponding CLRs independent of each other. I know the error is pretty clear, but somehow I still have hope of a workaround. – Michel Triana Sep 30 '10 at 16:15
  • 1
    As far as I can tell, this requires using the hosting interfaces http://msdn.microsoft.com/en-us/library/dd380851.aspx. There's a codeplex project to help use them from managed code http://clractivation.codeplex.com/ or duping some part of the system to do this for you (eg use COM to get at the 4.0 assemblies - http://blogs.msdn.com/b/clrteam/archive/2009/06/07/in-process-side-by-side-part-2-common-in-proc-sxs-scenarios.aspx [but old info]) – Tony Lee Oct 14 '10 at 00:52

1 Answers1

0

I give up. This simply cannot be done without making some serious compromises and various hacks with the GAC and COM registration as pointed out by Tony Lee (thanks for the links). I ended up rebuilding everything in 4.0.

Paraphrasing A. Einstein: ".NET is well and good but Microsoft keeps dragging us around by the nose"

:)

Thank you all for the comments and help.

Michel Triana
  • 2,486
  • 1
  • 22
  • 31