0

I started to have some exceptions where using the pseudoselector :first. This started to happen when I changed my target framework from 4 to 4.5.1 on visual studio. The same code was run before without any errors. Everything else with CsQuery seems to keep working fine.

On my project references I have CsQuery.1.3.5.124, I guess it could be a bug, not sure. It worked fine before.

any help?

Thanks.

There

Stack trace:

[ArgumentException: The key already existed in the dictionary.]
   System.Collections.Concurrent.ConcurrentDictionary`2.System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey key, TValue value) +10940468
   CsQuery.Engine.PseudoSelectors.PopulateFromAssembly(Assembly assy, String[] nameSpaces) +344
   CsQuery.Engine.PseudoSelectors.Register(Assembly assembly) +153
   CsQuery.Engine.PseudoSelectors.PopulateInnerSelectors() +305
   CsQuery.Engine.PseudoSelectors..ctor() +168
   CsQuery.Engine.PseudoSelectors..cctor() +44

[TypeInitializationException: The type initializer for 'CsQuery.Engine.PseudoSelectors' threw an exception.]
   CsQuery.Engine.PseudoSelectors.get_Items() +0
   CsQuery.Engine.SelectorParser.AddPseudoSelector(String key) +49
   CsQuery.Engine.SelectorParser.Parse(String selector) +2360
   CsQuery.Engine.Selector..ctor(String selector) +103
   CsQuery.CQ.Select(String selector) +83
   CsQuery.CQ.get_Item(String selector) +42
VMh
  • 1,300
  • 1
  • 13
  • 19

2 Answers2

1

This should only happen if there are custom pseudoselectors in your project, and further two of them with the same name. If you are just using straight CsQuery then I can't think why this would happen.

When CsQuery starts, by default, it will scan the calling assembly for classes that implement IPseudoSelector and attempt to register it. You can disable the automatic scanning for custom pseudoselectors with this (before running any selectors):

CsQuery.Config.StartupOptions = 0;

If you are actually using custom pseudoselectors you can register them manually as well, see this blog post for details:

http://blog.outsharked.com/2012/07/csquery-113-released.html

I can't think of any reason why changing frameworks would cause this to happen, so maybe it's just a coincidence, but hopefully this will give you the information you need to solve the problem.

Jamie Treworgy
  • 23,934
  • 8
  • 76
  • 119
0

Yes, I have a custom pseudoselector implemented. The problem seems to be fixed now.

The problem was happening on a project that references another project where the pseudoselector is defined. Both project had references to CSQuery but different versions. I replaced the older version (in the project where the pseudoselector is defined) with the newest same version I have in the project where the problem is taking place.

Now it seems everything is back ok.

Thanks for your help!!

VMh
  • 1,300
  • 1
  • 13
  • 19