[英]C# Generic List constructor gives me a MethodAccessException
I make a list in my code like so: 我在代码中列出一个清单,如下所示:
List<IConnection> connections = new List<IConnection>();
where IConnection is my own interface. IConnection是我自己的接口。 This is in a .NET 2.0 executable. 这在.NET 2.0可执行文件中。 If I run the code on my machine (with lots of .Net versions installed) it works fine. 如果我在计算机上运行代码(安装了许多.Net版本),则可以正常运行。 If I run it on my test machine (which only has .NET 3.5 SP1 installed) then I get a MethodAccessException in the System.Collections.Generic.List constructor. 如果在测试计算机(仅安装了.NET 3.5 SP1)上运行它,则在System.Collections.Generic.List构造函数中会收到MethodAccessException。 Any ideas what could be going wrong? 任何想法可能出什么问题吗?
Just to remove some possibilities - re-build your code by replacing: 只是为了消除一些可能性-通过替换来重新构建代码:
List<IConnection> connections = new List<IConnection>();
with 与
List<int> connections = new List<int>();
In other words, it might be helpful to know if the list can be created with a type other then IConnection
. 换句话说,了解列表是否可以使用IConnection
的类型创建可能会有所帮助。
I'm not sure where to take it after that, but at least give this a go, to see if you can get your code to run at all. 我不确定之后该怎么做,但至少可以尝试一下,看看是否可以完全运行您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.