30

Can you use a .NET 4.0 dll in a 3.5 project?

3
  • 11
    Is anything ever forward-compatible? Commented Sep 24, 2010 at 21:21
  • 3
    You can if you don't mind creating a COM wrapper/adapter and calling the .NET 4 DLL through that stackoverflow.com/a/9508452/74585 Commented Feb 29, 2012 at 23:50
  • Please check my other answer to the same question: stackoverflow.com/questions/16038442/… Commented Apr 17, 2013 at 19:58

3 Answers 3

26

Nope. You can use a .Net 3.5 assembly in a 4.0 project, but not the other way around.

Sign up to request clarification or add additional context in comments.

Comments

17

No you can't. An assembly compiled against .NET 4.0 can be loaded only by the CLR 4.0. On the other hand the CLR 4.0 can load assemblies compiled against .NET 3.5.

3 Comments

CLR 4.0 loading a 3.5 assembly surprised and confused me the other day. Scratched my head over that one for a bit.
@Jim, why? If this wasn't possible I cannot even imagine ever migrating to .NET 4.0. Microsoft have always done a good job at keeping backwards compatibility when releasing new versions of the framework/CLR.
I don't know why it surprised me. In retrospect, it shouldn't have. But for some reason at the time I didn't expect it.
0

https://code.msdn.microsoft.com/Using-a-NET-4-Based-DLL-bb141db3/

Use our .NET 4 DLL via COM

 using System; using Net4ToNet2Adapter; namespace Net2Assembly { class Program { static void Main(string[] args) { Console.WriteLine("CLR version from EXE: {0}", Environment.Version); Type myClassAdapterType = Type.GetTypeFromProgID("Net4ToNet2Adapter.MyClassAdapter"); object myClassAdapterInstance = Activator.CreateInstance(myClassAdapterType); IMyClassAdapter myClassAdapter = (IMyClassAdapter)myClassAdapterInstance; myClassAdapter.DoNet4Action(); } } } 

1 Comment

Why is this not the accepted answer? I haven't tested it yet, but I will tomorrow.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.