1

I need to have a DLL built in .net v2.0 to be called from SQL Server 2008 as an external DLL (CLR Assembly). This dll must be in .net v2.0 to be compatible with our SQL Server version and is only to make a bridge between SQL Server and other C# features developed in .net V4.5. So i refence another DLL built in .Net V4.5 but I can't compile it! I have the fallowing warning:

warning MSB3258: The primary reference "my_dll" 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.

Can we ignore the assembly version compability ? Or can we have another solution to invoke any function developed in .net V.4.5 from a SQL Server 2008 ?

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76
Mr. Green
  • 19
  • 1
  • 2
    This cannot work because the CLR version of your SQL Server is 2.0 as well. It cannot load a 4.5 assembly, not even if that assembly referenced no other system assemblies at all (which of course it does). Recompile *all* assemblies involved to target .NET 2.0, or upgrade your server. – Jeroen Mostert Jan 28 '17 at 19:21
  • @JeroenMostert looks like you typed an answer into the comment box. – Martin Smith Jan 28 '17 at 19:41
  • @MartinSmith: I know, but that's because I hate to give the answer "no you can't possibly do this" without my problem-loving brain running off and trying very, very hard to find some solution anyway ("Maybe you could abuse COM! Maybe you could futz with the assembly version header in this case! Maybe..." SHUT UP). And the OP did ask for another solution, and I know questions that already have an answer attract less eyes. ...I'll stop rambling now. – Jeroen Mostert Jan 28 '17 at 19:47
  • The only possibility to make this work (that I can think of) is some other out-of-process component that targets the 4.0 CLR, and an IPC mechanism. To be honest you're going to go through a lot of grief to get it working cleanly. Jeroen's comment is really the right answer - upgrade SQL. – lesscode Jan 28 '17 at 20:23

2 Answers2

0

I'm not sure I'm following your question but to answer it you just need change the project dependency to .NET 4.5. .NET frameworks can reference other framework versions but you have to consider the order of dependency. If the 2.0 is using a 4.0 library then it will fail because it doesn't have a reference of it's own to the components. When your project is compiled it's placed into a single Assembly and that assembly must have reference to all ingredients being used. However; if your projects are separate dll's which is sounds like they are then you can reference between them as long as the 4.0 members aren't exposed publicly in the assembly. However; that means the dll requires an environment with 4.0 installed in order for itself to operate.

In order to run different versions of the same assemblies you would need to add an assemblyBinding to your project configuration.

It's a bit hard to follow but look at this post and see if it helps you better understand how to achieve this.

Post

Community
  • 1
  • 1
Michael Puckett II
  • 6,586
  • 5
  • 26
  • 46
0

As per this answer here, it is possible to reference the .Net 4.5 assembly by exposing the components required as COM. All versions of .Net are based on COM at it's core, so it can be used as a 'lowest common denominator' channel of communication. Depending on your requirements, you may also want to look into using Named Pipes, IPC or even Web Services.

Community
  • 1
  • 1
Willem van Ketwich
  • 5,666
  • 7
  • 49
  • 57