2015-02-05 111 views
0

我开始在使用伪选择器的地方有一些例外:第一。当我在Visual Studio中将我的目标框架从4改为4.5.1时,就开始发生这种情况。之前运行的代码没有任何错误。使用CsQuery的其他一切似乎都能正常工作。CsQuery伪选择器异常

在我的项目引用我有CsQuery.1.3.5.124,我想这可能是一个错误,不知道。它以前工作得很好。

有帮助吗?

谢谢。

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 
+0

你能分享你的代码吗? – 2015-02-06 12:16:03

回答

1

如果在您的项目都是定制pseudoselectors这应该只发生,而另外两个人具有相同的名称。如果你只是使用直接的CsQuery,那么我想不出为什么会发生这种情况。

CsQuery启动时,默认情况下,它将扫描调用程序集中实现IPseudoSelector的类并尝试注册它。您可以禁用与此自定义pseudoselectors自动扫描(运行任何选择前):如果您在实际使用自定义pseudoselectors你可以手动将其注册为好,详见本博客文章

CsQuery.Config.StartupOptions = 0; 

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

我想不出为什么改变框架会导致这种情况发生,所以也许这只是一个巧合,但希望这会给你提供解决问题所需的信息。

0

是的,我有一个自定义的pseudoselector实现。这个问题现在似乎已经解决了。

问题发生在引用其中定义了伪选择器的另一个项目的项目上。这两个项目都引用了CSQuery,但版本不同。我用项目中发生问题的最新版本取代了旧版本(在定义了伪选择器的项目中)。

现在看来一切都恢复了。

感谢您的帮助!