views:

103

answers:

2

I'm trying to evaluate an expression stored in a database i.e.

"if (Q1 ==2) {result = 3.1;} elseif (Q1 ==3){result=4.1;} else result = 5.9;"

Rather than parsing it myself I'm trying to use the DLR. I'm using version .92 from the Codeplex repository and my solution is a .NET 3.5 website; and I'm having conflicts between the System.Core and Microsoft.Scripting.ExtenstionAttribute .dll's.

Error =
{
  Description: "'ExtensionAttribute' is ambiguous in the namespace 'System.Runtime.CompilerServices'.", 
  File: "InternalXmlHelper.vb"
}

At this time I cannot upgrade to .NET 4.0 and make significant use of the .net 3.5 features (so downgrading is not an option).

Any help greatly appreciated.

A: 

I might be to complex thinking right now and more easy solutions exists, but this jumped into my mind as a possibility;

Have you considered building a runtime class using the CodeDom, instanciating one, executing a method on it (with the expression as its implementation, which is more like code-snippets than a pure expression) and then retrieving the 'result' value from that class instance via a public property?

Marvin Smit
+1  A: 

The solution is to type forward ExtensionAttribte into System.Core.dll. We've made 3 different versions of this assembly (for the 3 different versions that we've shipped w/ various IronPython versions) and attached to them on this bug on IronPython's CodePlex site.

You'll need to download them and check the versions on them and replace the one that matches the version in the CodePlex release you're using.

Dino Viehland
Do I add the dll's to the GAC or to the assembly? Do I need one for Microsoft.Scripting.Core and Microsoft.Scripting? Is the source for the ExtensionAttribute with type forwarding available somewhere?
Aplato
You replace it wherever you have the existing one. If you put it in the GAC replace it there. You just need the one - it'll fix both M.S.Core.dll and M.S.dll.The source isn't that very interesting, it's just:[assembly: TypeForwardedTo(typeof(ExtensionAttribute))]And has a referene to System.Core.
Dino Viehland