Ruan
Ruan

Reputation: 4283

A reference to the dll could not be added. The component is Automatically Referenced C#

I am getting an error in C# Visual Studio and there doesn't seem to be any clear-to-the-point answer to this question online.

When I want to add mscorlib, I get this error message:

A reference to 'mscorlib' could not be added. This component is automatically referenced by the project system and cannot be referenced directly.

but .EnumerateFiles() needs that library.

Why would this message show when one want to add a specific reference?

Upvotes: 1

Views: 8141

Answers (2)

Alexei Levenkov
Alexei Levenkov

Reputation: 100527

MSDN is good place to solve such mysteries -DirectoryInfo.EnumerateFiles clearly shows that it is supported by 4.0 and 4.5 versions of .NET.

You are trying to link against 2.0 (or maybe something like 3.0/3.5) and do not have such function. Your error clearly says that you can't add the assembly to the project since it is always referenced automatically for correct version of runtime.

To be able to use the new EnumerateFile, you need to build against 4.0+, or write code without that function.

Upvotes: 3

Saurabh R S
Saurabh R S

Reputation: 3177

EnumerateFiles require .NET 4 or later. I think you are building your solution targetting .NET Framework 3.5 or earlier.

Upvotes: 2

Related Questions