sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

Fix "Operation could destabilize the runtime" error when passing a dicti... #42

Closed forbjok closed 10 years ago

forbjok commented 10 years ago

Workaround for what appears to be a bug in CavemanTools - if .ToDictionary() is called on a dictionary, it will fail with the rather uninformative exception "Operation could destabilize the runtime". This works around it by simply checking if the data object implements IDictionary<string, object> and if so, not running ToDictionary() on it, since it doesn't need to be converted anyway.

DavidKarlas commented 10 years ago

What is difference between:

if (data.GetType().GetInterfaces().Contains(typeof(IDictionary<string, object>)))

and

if (data is IDictionary<string, object>)

Because it seems to me like second is faster and more readable...

sapiens commented 10 years ago

@forbjok I've fixed the bug in caveman tools (v3.15.1 ). For future Pull Requests please use the 'Devel' branch.

@DavidKarlas Indeed the second option is the optimum one.

Thank you both for your help.