开发者

C# Generic List constructor gives me a MethodAccessException

开发者 https://www.devze.com 2023-01-03 09:44 出处:网络
I make a list in my code like so: List<IConnection> connections 开发者_StackOverflow社区= new List<IConnection>();

I make a list in my code like so:

List<IConnection> connections 开发者_StackOverflow社区= new List<IConnection>();

where IConnection is my own interface. This is in a .NET 2.0 executable. If I run the code on my machine (with lots of .Net versions installed) it works fine. 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. 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消