views:

254

answers:

4

Can someone help me find a solution to the following error:

"fatal error C1190: managed targeted code requires a '/clr' option"

My configuration is ..

  • Visual studio 2008
  • Windows 7

Here is the code (i got by using net resources)

#using <mscorlib.dll>
using namespace System;
using namespace System::IO;

int main() {
    // Create a reference to the current directory.
    DirectoryInfo* di = new DirectoryInfo(Environment::CurrentDirectory);
    // Create an array representing the files in the current directory.
    FileInfo* fi[] = di->GetFiles();
    Console::WriteLine(S"The following files exist in the current directory:");
    // Print out the names of the files in the current directory.
    Collections::IEnumerator* myEnum = fi->GetEnumerator();
    while (myEnum->MoveNext()) {
        FileInfo* fiTemp = __try_cast<FileInfo*>(myEnum->Current);
        Console::WriteLine(fiTemp->Name);
    }
}
+4  A: 

Just do what the error message suggests. It says that you have to enable the /clr option when using managed code, which is what you're doing. Either add the /clr switch to the compiler command line, or enable CLR (Common Language Runtime) support in the project settings.

OregonGhost
A: 

Thanx for Your reply but i wana know how to do this.............

A: 

Ok i have done with your Idea it works..... but know i found a new error.........

fatal error C1083: Cannot open include file: 'mscorlib.dll': No such file or directory

. what to do now??

A: 

I believe that mscorlib is automatically linked in, instead of you having to manually refer it.

DeadMG