In the comment on the 6th floor of the previous article "talking about the C # interaction window", diryboy yuanyou pointed out that the error in running csharp.exe in the Windows operating system seems to be. net 4 new security rules are at work, and a website is provided to solve similar problems. The specific reason is. NET framework 4 introduces two levels of transparency ,. NET framework 4 Rules use level 2 transparency (securityruleset. level2), and. net Framework 2.0 Rules use the first level of transparency (securityruleset. level1 ). Therefore, in the C # source of mono. CSHARP. dllProgramCodeYou can solve this problem by adding the following statement to the assemblyinfo. CS file:
[Assembly:Securityrules(Securityruleset. Level1)]
However, Mono compilation in the Ubuntu operating system will fail.
In mono 2.8.1, only about 60 C # source programs related to csharp.exe and mono. CSHARP. dll are distributed in the following directories:
Mono. CSHARP. dll requires the following 57 C # source files:
.. \.. \ MCS \ anonymous. CS .. \.. \ MCS \ argument. CS .. \.. \ MCS \ assign. CS .. \.. \ MCS \ attribute. CS .. \.. \ MCS \ cs-tokenizer.cs .. \.. \ MCS \ cfold. CS .. \.. \ MCS \ class. CS .. \.. \ MCS \ codegen. CS .. \.. \ MCS \ complete. CS .. \.. \ MCS \ Const. CS .. \.. \ MCS \ constant. CS .. \.. \ MCS \ convert. CS .. \.. \ MCS \ context. CS .. \.. \ MCS \ Decl. CS .. \.. \ MCS \ delegate. CS .. \.. \ MCS \ doc. CS .. \.. \ MCS \ doc-bootstrap.cs .. \.. \ MCS \ driver. CS .. \.. \ MCS \ Dynamic. CS .. \.. \ MCS \ ecore. CS .. \.. \ MCS \ Enum. CS .. \.. \ MCS \ eval. CS .. \.. \ MCS \ expression. CS .. \.. \ MCS \ field. CS .. \.. \ MCS \ flowanalysis. CS .. \.. \ MCS \ Generic. CS .. \.. \ MCS \ import. CS .. \.. \ MCS \ iterators. CS .. \.. \ MCS \ lambda. CS .. \.. \ MCS \ LINQ. CS .. \.. \ MCS \ literal. CS .. \.. \ MCS \ location. CS .. \.. \ MCS \ membercache. CS .. \.. \ MCS \ method. CS .. \.. \ MCS \ modifiers. CS .. \.. \ MCS \ namespace. CS .. \.. \ MCS \ nullable. CS .. \.. \ MCS \ parameter. CS .. \.. \ MCS \ pending. CS .. \.. \ MCS \ property. CS .. \.. \ MCS \ report. CS .. \.. \ MCS \ rootcontext. CS .. \.. \ MCS \ roottypes. CS .. \.. \ MCS \ statement. CS .. \.. \ MCS \ support. CS .. \.. \ MCS \ typemanager. CS .. \.. \ MCS \ typespec. CS .. \.. \ MCS \ visit. CS .. \.. \ MCS \ symbolwriter. CS .. \.. \ class \ mono. compilerservices. symbolwriter \ monosymbolfile. CS .. \.. \ class \ mono. compilerservices. symbolwriter \ monosymboltable. CS .. \.. \ class \ mono. compilerservices. symbolwriter \ monosymbolwriter. CS .. \.. \ class \ corlib \ mono. security. cryptography \ cryptoconvert. CS .. \.. \ build \ common \ consts. CS .. \.. \ tools \ MonoP \ outline. CS .. \.. \ MCS \ cs-parser.csAssembly \ assemblyinfo. CS
This is the content of the MCS/class/mono. CSHARP. dll. Sources file. Note that the directory delimiter in this file is "/" of the Linux operating system, and I am replacing it with "\" of the Windows operating system.
Csharp.exe only requires the following three C # source files:
.. \ Class \ corlib \ mono \ dataconverter. csrepl. csgetline. CS
This is the content of the MCS/tools/CSHARP/csharp.exe. Sources file. Then, refer to the previous article and add the following sentence after the 59th lines of the MCS/tools/CSHARP/REPL. CS file:
Console. Writeline (Ex );
Edit the following Mak. CMD file for compilation:
@ Echo offcd MCS \ class \ mono. csharpcsc-T: Library-out :.. \.. \.. \ mono. CSHARP. DLL-D: net_4_0 @ mono. CSHARP. DLL. sources> .. \.. \.. \ mono.csharp.txt CD .. \.. \ tools \ csharpcsc/unsafe-out :.. \.. \.. \ csharp.exe-D: on_dotnet-R :.. \.. \.. \ mono. CSHARP. DLL @csharp.exe. sources> .. \.. \.. \ csharp.exe.txt CD .. \.. \.. sn-r mono. CSHARP. dll mcs \ class \ mono. SNK> sn.txt
The compilation and running results are as follows:
E: \ CS \ csharprepl \ mono>MakE: \ CS \ csharprepl \ mono>CSHARPSystem. typeloadexception: override member "Mono. CSHARP. streamreportprinter. Print (mono. CSHARP. abstractmessage)" violates the inherited security rules. The security accessibility of the override method must match the Security accessibility of the method to be rewritten. In mono. CSHARP. evaluator. initandgetstartupfiles (string [] ARGs) at mono. Driver. startup (string [] ARGs) E: \ CS \ csharprepl \ mono>
This is the same as the error in the previous article. Now let's add the following statement to the MCS/class/mono. CSHARP/ASSEMBLY/assemblyinfo. CS file:
[Assembly:Securityrules(Securityruleset. Level1)]
Then re-compile and run:
E: \ CS \ csharprepl \ mono>MakE: \ CS \ csharprepl \ mono>CSHARP -- versionMono C # compiler version 4.0.0.0e: \ CS \ csharprepl \ mono>CSHARPMono C # shell, type "help;" for helpenter statements below. CSHARP>Environment. osversion;Microsoft Windows NT 6.0.6002 Service Pack 2 CSHARP>Environment. version;4.0.30319.1csharp>Quit;E: \ CS \ csharprepl \ mono>
Finally, the C # interactive window is implemented in the Windows operating system. Instead of installing mono, you only need the mono. CSHARP. dll and csharp.exe files.
In addition, you can add mono. CSHARP. DLL to the Global Assembly Cache (administrator privilege required ):
E: \ CS \ csharprepl \ mono>Gacutil/I mono. CSHARP. dllMicrosoft (R). Net Global Assembly Cache utility. Version 4.0.30319.1 copyright (c) Microsoft Corporation. All rights reserved. The Assembly has been successfully added to the cache. E: \ CS \ csharprepl \ mono>Gacutil/L mono. CSHARPMicrosoft (R). Net Global Assembly Cache utility. Version 4.0.30319.1 copyright (c) Microsoft Corporation. All rights reserved. The Global Assembly Cache contains the following Assembly: Mono. CSHARP, version = 4.0.0.0, culture = neutral, publickeytoken = 0738eb9f132ed756, processorarchitecture = msil project COUNT = 1E: \ CS \ csharprepl \ mono>
Then, place csharp.exe in the path directory to run the C # interaction window at any time.
Finally, all the programs mentioned in this article can be downloaded here.