Using a .NET 4 Based DLL From a .NET 2 Based Application

This sample show how you can call methods from a .NET 4 DLL from a .NET 2 executable.

C# (87.1 KB)
3.7 Star
3,906 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Handle com events in managed client application
    1 Posts | Last post November 27, 2017
    • Thank for sharing this post. I have successfully implemented your solution in my project and it is working fine. I want to implement event functionality for raising events from com component and handle in client app [Windows Application]. I have gone through many blogs and articles but most of them are implemented in native and some are using native components like ActiveX or explorer. Also there is no client side implementation. It would be great if you provide example for implementing event handling.
  • Calling app is a WinForm exe - code does not work
    4 Posts | Last post September 24, 2014
    • Sorry for possible cross-post.I can not seem to post on your blog.
      Great idea with manifests but your code does not work with WinForm exe's. It bombs on this line
      object myClassAdapterInstance = Activator.CreateInstance(myClassAdapterType);
      The error is:
      Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80070002.
      Try converting your console app into a .net 2.0 WinForm exe and you can see the error right away. 
      My environment is Windows 7 64 bit if it makes any difference. 
      Please help. 
      Many thanks in advance
    • Is there already a solution?
    • Hi Arik
      Thank you for sharing such interesting experience.
      in my case it fails even to start my test WinForms application with error message 'because application configuraion is incorrect'
      However my test console application is started without any problem
      I've removed net2 application manifest and have executed regasm (from .net 4 :\Windows\Microsoft.NET\Framework\v4.0.30319\) for Net4ToNet2Adapter assembly in the Net2Assembly output folder. And WindowsApplication sample was able to access a net4assembly (com object instance was created and method was called). Seems that it is exactly the same registry records that is ommited using app.manifest files.
      Seems that I have to wrote a wcf service that will do .net4 job for my .net2 application, this looks too tricky to use in production
    • hi
      I have tried to use Winforms and it failed as well. Then I have changed the Properties>Build>Target to x86 and it has worked.