带有 .Net 2.0 WinForms 应用程序的 VS2010 - 绑定到通用列表时出错
我最近转换为 Visual Studio 2010,并在一个在 VS2008 中完美运行的项目上运行了转换。 Visual Studio 2010 中的情况就不那么乐观了。
这是一个 .Net 2.0 WinForms 项目,它大量使用将 ListView 和 Grid 绑定到通用列表,因此取出通用列表是不可行的。
我收到以下错误消息(出于发布目的而匿名):
Could not find a type for a name. The type name was
'System.Collections.Generic.List`1[[MyAttribute, Domain, Version=1.0.0.5,
Culture=neutral, PublicKeyToken=71c8708be064889a]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'. Line 134, position 5.
C:\Projects\MyProject\Control.resx
如果我将项目升级到 .net 4.0,问题就会消失,但该项目必须以 .net 2.0 为目标,因此这不是合适的长期解决方案。
谷歌搜索发现了大量来自/有/问题的人的帖子,但我看不到任何已经解决了问题的人的帖子,所以任何帮助将不胜感激。
塔。
I've recently converted to Visual Studio 2010 and ran the conversion on a project that worked perfectly in VS2008. Things are not so sunny in Visual Studio 2010.
This is a .Net 2.0 WinForms project that makes a lot of use of binding ListViews and Grids to Generic Lists so taking out the Generic Lists isn't feasible.
I get the following error message (anonymised for posting purposes):
Could not find a type for a name. The type name was
'System.Collections.Generic.List`1[[MyAttribute, Domain, Version=1.0.0.5,
Culture=neutral, PublicKeyToken=71c8708be064889a]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'. Line 134, position 5.
C:\Projects\MyProject\Control.resx
The problem goes away if I roll the project up to .net 4.0 but this project has to target .net 2.0 so that's not a suitable long-term solution.
Googling around finds plenty of posts from people /having/ the problem but none that I can see from people who have solved the problem so any help would be greatly appreciated.
Ta.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除 .resx 文件中的部分,然后删除 Designer.cs 中加载该资源的行 (
resources.GetObject("...")
)。然后尝试在设计器中打开控件,两者都应该重新生成,您可能会收到空引用异常,具体取决于公开在设计器中设置的属性的控件。对我来说,我可以忽略并继续。
设计器出现后,您可以比较 resx 文件,并看到无论它是什么对象,现在的序列化都略有不同。此外,如果它是您的自定义控件并且您要公开通用列表属性,请考虑首先在其上放置
[Browsable(false)]
属性,这样您就无法从设计器设置值,并且设计器也不会自动设置到一个新的值。在我的例子中发生的情况是一个空的通用列表被序列化到 resx 文件,然后在升级 Visual Studio 后,列表不再以相同的方式序列化。
Delete the section in the .resx file and then also delete the line in the designer.cs (
resources.GetObject("...")
)that's loading that resource.Then try opening the control in the designer and both should get regenerated, you might get a null reference exception depending on the control that's exposing a property that gets set in the designer. For me I was able to ignore and continue.
After the designer appears you can compare the resx file and see that whatever object it was is now serialized a little differently. Also if it's your custom control and you are exposing a generic list property consider putting the
[Browsable(false)]
attribute on it first so you cannot set the value from the designer and the designer will not automatically set it to a new value.What was happening in my case was an empty generic list was serialized to the resx file and then after upgrading visual studio the list no longer serialized the same way.
这里没有太多信息可以继续。
看起来像是序列化问题。您是否正在序列化控件上的集合属性?需要序列化吗?
如果不需要,请尝试添加 DesignerSerializationVisibility 属性。默认情况下它会尝试序列化所有属性。
Not much to info to go on here..
Looks like a serialization problem. Are you serializing a collection property on control? Does it need to be serialized?
If it's not needed try adding a DesignerSerializationVisibility attribute. It tries to serialize all properties by default.
我们也发现了这一点...我们的 VS2008 项目包含一个公开通用列表的属性,在构建时将得到相同的异常。我们在 VS2010 构建机器上使用 MSBuild 3.5(它安装了 2010,但我们还无法将项目升级到 2010 格式)。
我们的错误来自于一种形式:
TBDEV830.resx (143):找不到名称的类型。类型名称为 'System.Collections.ObjectModel.ObservableCollection`1[[T1.Tb.SideBar.ISideBar, T1.Tb.SideBar, Version=1.0.3702.18460, Culture=neutral, PublicKeyToken=null]], WindowsBase, Version= 3.0.0.0,文化=中立,PublicKeyToken=31bf3856ad364e35'。第 143 行,位置 5。
从其他论坛找到了一些帖子,但似乎还没有人找到解决方案:
一篇文章指出添加 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 但这没有影响。
另一篇文章 (http://www.go4answers.com/Example/tfs2008-tfs2010-migration-upgrade-3526.aspx) 指出将其加载到 IDE 中并询问这是否有助于隔离问题,但这意味着升级项目到 2010 格式,这是 ew 做不到的。
We are finding this too... Our VS2008 projects that contain a property that exposes a generic list will get the same exception when building. We are using MSBuild 3.5 on a VS2010 build machine (it has 2010 installed, but we can't upgrade the projects to 2010 format yet).
Our error comes from a form:
TBDEV830.resx (143): Could not find a type for a name. The type name was 'System.Collections.ObjectModel.ObservableCollection`1[[T1.Tb.SideBar.ISideBar, T1.Tb.SideBar, Version=1.0.3702.18460, Culture=neutral, PublicKeyToken=null]], WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Line 143, position 5.
Have found a few posts from other forums and no-one seems to have found a solution yet:
One article states to add [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] but this has no affect.
Another article (http://www.go4answers.com/Example/tfs2008-tfs2010-migration-upgrade-3526.aspx) states to load it in the IDE and asks if that helps isolate the problem, but that would mean upgrading the project to 2010 format, which ew can't do.