none
How to Call a Function in a dll built in higher version of .NET RRS feed

  • Question

  • I have a CLR assembly built in .NET 3.5 in a SQL Server 2008R2. I need to be able to call a function in a .NET dll built in .NET 4.6.1. I can't reference the dll from my CLR project, as I get errors like the following, since SQL Server 2008R2 doesn't support higher than 3.5:

    The primary reference "MyClrProject" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.

    How can I call a function in a dll that is build in a higher .NET version from my .NET 3.5 assembly?

    Tuesday, July 23, 2019 2:08 AM

Answers

  • I was able to solve this by exposing the .NET 4.6.1 dll to COM. I could then call it from the CLR assembly.
    • Marked as answer by Alphonse G Monday, August 5, 2019 6:39 PM
    Monday, August 5, 2019 6:39 PM

All replies

  • How can I call a function in a dll that is build in a higher .NET version from my .NET 3.5 assembly?

    It's simply not possible.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Tuesday, July 23, 2019 6:19 AM
  • Thanks Olaf.

    What if I make the .NET 4 dll into a console app. Any way to call that, either directly from a stored procedure or CLR?

    Tuesday, July 23, 2019 10:34 AM
  • What if I make the .NET 4 dll into a console app. Any way to call that, either directly from a stored procedure or CLR?

    There would quite an overhead for accessing the console application.

    You said that the assembly was .NET 3.5, but as I recall SQL 2008 assumes .NET 2.0, but maybe later versions work. In that case you would build a .NET 4 DLL and try.

    Then again, SQL 2008 R2 is out of support, so maybe it is time to upgrade?


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    Tuesday, July 23, 2019 11:21 AM
  • Thanks Erland. Yes, much of 3.5 is 2.0. I did try referencing the 4.x assembly, and got the error mentioned in my original post when trying to build the project. Upgrade would be the best solution. Client was supposed to upgrade to 2016, 2 years ago as part of moving infrastructure to the cloud, then stopped, then one year ago, then stopped. Supposedly coming soon, but I need to do this now.

    I was hoping that there was a way to create some kind of wrapper for the .NET 4 project, so SQL server would only see 3.5.

    Tuesday, July 23, 2019 11:34 AM
  • I was able to solve this by exposing the .NET 4.6.1 dll to COM. I could then call it from the CLR assembly.
    • Marked as answer by Alphonse G Monday, August 5, 2019 6:39 PM
    Monday, August 5, 2019 6:39 PM