evilfred
evilfred

Reputation: 2416

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. 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?

Upvotes: 0

Views: 825

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

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.

Upvotes: 1

Related Questions