16

I have the need to make a call to the System.Xaml library in .NET 4.0. Is it possible to make a call to this library if your project is targeted to 3.5?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
mrwayne
  • 627
  • 6
  • 15
  • 3
    Well, you could compile that other lib as an exe, perhaps add a wrapper to it, and make the two modules communicate through sockets, files, shell ... but that would surely be ugly. – Hamish Grubijan May 03 '10 at 22:36
  • 1
    Have a look at the [Reactive Extensions](http://msdn.microsoft.com/en-us/data/gg577609) from Microsoft. It's a kind of backwards compatibility library for 3.5 – David d C e Freitas May 10 '11 at 12:41
  • Possible duplicate of [how to integrate .net library (.dll) from higher version (.net 4) with binaries from lower version (.net 2)](https://stackoverflow.com/questions/4377219/how-to-integrate-net-library-dll-from-higher-version-net-4-with-binaries) – Liam Oct 12 '17 at 12:11

4 Answers4

11

No. You'll need to target your project to run in .NET 4, and to use the CLR v4, in order to use .NET 4 assemblies.


On a different note - there is no real advantage here. Just change your application to target .NET 4. If you are going to add a dependency on the .NET 4 framework assemblies, you might as well just target .NET 4 in the first place...

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • The problem is, at the moment i only have VS2008, and i need a particular feature of Xaml (Serialization) in .net 4.0. I was hoping to be able to load it with reflection or something. – mrwayne May 04 '10 at 07:10
  • You can get hold of VS2010 very soon. Re-shuffle the projects' order. – Hamish Grubijan May 04 '10 at 14:07
  • @mrwayne: You can always use VS 2010 Express (available now): http://www.microsoft.com/express/ – Reed Copsey May 04 '10 at 18:18
  • Yeah, unfortunately its a bit more complicated than that, i'm in a work place that would need the entire development team to be upgraded, which means the software needs to be backwards compatibility tested moving to .net 4 ect ect. – mrwayne May 04 '10 at 22:26
  • 2
    @mrwayne: If you're working in that type of environment, adding a dep. on .NET 4 is probably not a good idea, either. I'd wait until your company does a full migration to .NET 4. – Reed Copsey May 04 '10 at 23:13
9

Here's a kind of Rube Goldberg-esque solution which involves wrapping your .NET 4 DLL methods in COM, and then calling that COM wrapper from .NET 3.5:

https://www.codeproject.com/Articles/204406/How-To-Use-a-NET-Based-DLL-From-NET-Based-Appl

Community
  • 1
  • 1
Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
2

No, you can't the assembly is mapped differently, one thing that you could do but that's a pain is to create a type in memory that reassembles your net 4.0 dll.

You could use CECIL to get IL instructions.

If you don't know IL very much don't even try to do it.

0

This question is similar to "how can I use a .NET 2 assembly in .NET 1.x application". It is impossible to add the assembly for new CLR as a reference, but like Hamish pointed out, inter process communication may help.

Lex Li
  • 60,503
  • 9
  • 116
  • 147