为什么我会收到此 .NET 错误 - “TypeError:预期 List[DataPoint],得到 List[DataPoint]”
我重构了一些代码,现在调用函数时出现此错误。但一切似乎都很好,我什至比较了新旧代码之间的 failing_argument.GetType().AssemblyQualifiedName
,它们是相同的。有什么想法可能是错的吗?
该函数的调用是在 IronPython 代码中,该函数是在 C# 代码中(在此重构期间未更改的程序集)。
什么样的事情会产生这个错误?
编辑:完整的 IronPython 回溯:
Traceback (most recent call last):
File "D:\Work\Framework\python\ide\tab_manager.py", line 57, in add_chart_tab
chart_tab = ChartTab(self.__main_window, self, tab_item, name, chart_descriptor)
File "D:\Work\Framework\python\ide\chart_tab.py", line 64, in __init__
self.__chart = Chart(self, self.__gui_cfg, self.__base_cfg, self.__chart_descriptor, self.__scroll_bar)
File "D:\Work\Framework\python\ide\chart.py", line 57, in __init__
self.update_topology(empty=False)
File "D:\Work\Framework\python\ide\chart.py", line 93, in update_topology
self.update_config()
File "D:\Work\Framework\python\ide\chart.py", line 111, in update_config
self.__global.chart_view = ChartView(self.__global)
File "D:\Work\Framework\python\ide\chart_view.py", line 33, in __init__
self.__spans = SpanUtil.compute_spans(time_series, gap_threshold)
TypeError: expected List[DataPoint], got List[DataPoint]
I refactored some code, and now I get this error when calling a function. But everything seems to be fine, I even compared failing_argument.GetType().AssemblyQualifiedName
between the old and the new code and they are the same. Any ideas what could be wrong?
The invocation of the function is in IronPython code, the function is in C# code (an assembly which didn't change during this refactoring).
What sort of thing could generate this error?
EDIT: full IronPython traceback:
Traceback (most recent call last):
File "D:\Work\Framework\python\ide\tab_manager.py", line 57, in add_chart_tab
chart_tab = ChartTab(self.__main_window, self, tab_item, name, chart_descriptor)
File "D:\Work\Framework\python\ide\chart_tab.py", line 64, in __init__
self.__chart = Chart(self, self.__gui_cfg, self.__base_cfg, self.__chart_descriptor, self.__scroll_bar)
File "D:\Work\Framework\python\ide\chart.py", line 57, in __init__
self.update_topology(empty=False)
File "D:\Work\Framework\python\ide\chart.py", line 93, in update_topology
self.update_config()
File "D:\Work\Framework\python\ide\chart.py", line 111, in update_config
self.__global.chart_view = ChartView(self.__global)
File "D:\Work\Framework\python\ide\chart_view.py", line 33, in __init__
self.__spans = SpanUtil.compute_spans(time_series, gap_threshold)
TypeError: expected List[DataPoint], got List[DataPoint]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过进一步调试后,我设法从代码中获得不同的错误消息:
Unable tocast object of type 'List[DataPoint]' to 'List[DataPoint]'
搜索此内容产生了几篇解释的文章问题:
http ://www.infinitec.de/post/2008/05/InvalidCastException-Unable-to-cast-object-of-Type-X-to-X.aspx
http://geekswithblogs.net/rupreet/archive/2010/02/16 /137988.aspx
事实证明,包含
DataPoint
的程序集(来自List[DataPoint]
)在我的应用程序中从两个不同的位置加载了两次。在我的例子中,原因是当 Visual Studio 生成程序集时,它还会将所有其他引用的程序集复制到bin
文件夹中新生成的程序集旁边。但我还从其原始构建位置动态加载引用的程序集之一。After further debugging I managed to get a different error message from the code:
Unable to cast object of type 'List[DataPoint]' to 'List[DataPoint]'
Searching for this yielded a couple of articles explaining the problem:
http://www.infinitec.de/post/2008/05/InvalidCastException-Unable-to-cast-object-of-Type-X-to-X.aspx
http://geekswithblogs.net/rupreet/archive/2010/02/16/137988.aspx
It turns out that the assembly containing
DataPoint
(fromList[DataPoint]
) it's loaded twice in my application from two different locations. The cause in my case is that when Visual Studio builds an assembly, it also copies all the other referenced assemblies next to the newly built one in thebin
folder. But I also dynamically load one of the referenced assemblies from it's original build location.可能是类型解析的问题...使用完整的类型名称(包括命名空间)。一些代码示例可能会有所帮助!
May be an issue with the type resolution...use the complete type name (including the namespace). Some code sample might help!