1

I'm trying to use a Dictionary in a C# script block embedded in a XSLT1.0 doc. When I'm trying to add a reference to either System.Collections.Generic or System.Core, I'm getting a 'metadata file not found for assembly...' When adding ref to 'mscorlib', it seems like an older version is being referenced (?), since I'm getting an error when trying to use Dictionary.Keys.Contains() ('does not contain a Contains method). Needless to say, this code was tested successfully outside the xslt. How can I add a proper ref to a FW 3.5/4 ? Tnx!

1
  • Sharing the critical parts of your source code may help others to dig into your problem. Also, check this: how to ask good questions Commented Mar 10, 2015 at 19:22

1 Answer 1

2

Dictionary.Keys.Contains is defined in the System.Linq namespace, and Linq is defined in the System.Core assembly, so you'll need the right msxsl:assembly and msxsl:using elements for those. The following works for me in the VS2013 XSLT debugger:

<msxsl:script implements-prefix="my" language="csharp">
  <msxsl:assembly name="System.Core" />
  <msxsl:using namespace="System.Linq" />
  <msxsl:using namespace="System.Collections.Generic" />

  <![CDATA[
    public bool myFunc() 
    {
      var d = new Dictionary<string, string>();
      d.Add("Hello", "Goodbye");
      return d.Keys.Contains("Hello");
    }    
  ]]>
</msxsl:script>

This still leaves the question of why you are using Dictionary.Keys.Contains, when you could use Dictionary.ContainsKey, which has been in .NET since 2.0 and doesn't need any extra assembly or namespace references.

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

1 Comment

Thanks.Using ContainsKey indeed solved the 'no method' issue, however I'm still unable to reference System.Linq, Collections.Generic or Core. Any ideas? VS2010 btw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.