I also talked about using Scala on the. NET platform (below)

Source: Internet
Author: User
Tags dotnet mscorlib

In the first two articles, to run the scala. Net program, we need to copy predef. DLL to the current directory. This is unpleasant.

First, I thought of adding predef. DLL to the Global Assembly Cache (GAC, Global Assembly Cache), as shown below:

ben@ben-m4000t:~$ sudo gacutil -i /opt/scala-2.7.7.final/lib/predef.dll
Failure adding assembly /opt/scala-2.7.7.final/lib/predef.dll to the cache: Attempt to install an assembly without a strong name

Unfortunately, predef. dll is not a strong name and cannot be put into the global assembly cache. Here I want to criticize the author of scala-msil software package. How can such an important thing be a strong name?

 

Then, I will try another way. First, create a mono-extra directory under the/usr/local/lib directory and create the required predef. DLL and scalaruntime. DLL symbolic connection, as shown below:

ben@ben-m4000t:~$ cd /usr/local/lib
ben@ben-m4000t:/usr/local/lib$ sudo mkdir mono-extra
ben@ben-m4000t:/usr/local/lib$ cd mono-extra
ben@ben-m4000t:/usr/local/lib/mono-extra$ sudo ln -s /opt/scala-2.7.7.final/lib/predef.dll
ben@ben-m4000t:/usr/local/lib/mono-extra$ sudo ln -s /opt/scala-2.7.7.final/lib/scalaruntime.dll
ben@ben-m4000t:/usr/local/lib/mono-extra$ ls -l *
lrwxrwxrwx 1 root root 37 2009-12-23 14:36 predef.dll -> /opt/scala-2.7.7.final/lib/predef.dll
lrwxrwxrwx 1 root root 43 2009-12-23 14:37 scalaruntime.dll -> /opt/scala-2.7.7.final/lib/scalaruntime.dll
ben@ben-m4000t:/usr/local/lib/mono-extra$

Then, edit ~ /. Add the following content to the end of the bashrc file:

# set mono extra library pathif [ -d "/usr/local/lib/mono-extra" ] ; then    export MONO_PATH=/usr/local/lib/mono-extrafi

In this way, you can run the scala. Net program without copying predef. DLL to the current directory.

You can also process the DLL files you want to share.

Note that do not connect/opt/scala-2.7.7.final/lib/mscorlib. DLL to the/usr/local/lib/mono-extra directory. Otherwise, the following error occurs when running all. net programs:

ben@ben-m4000t:~/Projects/ScalaNet$ mono dotnet.exe
Corlib not in sync with this runtime: expected corlib version 69, found 65.
Loaded from: /opt/scala-2.7.7.final/lib/mscorlib.dll
Download a newer corlib or a newer runtime at http://www.go-mono.com/daily.

This is because scala. Net's mscorlib. dll version is 65 older, and CLR expects a newer version of corlib version 69.

 

So let's take a look at the versions of various mscorlib. DLL files on this machine.

2,070,528 2009-12-22 22:52 /opt/scala-2.7.7.final/lib/mscorlib.dll
2,076,672 2009-09-23 23:28          /usr/lib/mono/1.0/mscorlib.dll
2,092,544 2009-12-23 20:09 /opt/mono-2.6/lib/mono/1.0/mscorlib.dll
2,565,632 2009-09-23 23:29          /usr/lib/mono/2.0/mscorlib.dll
2,586,624 2009-12-23 20:11 /opt/mono-2.6/lib/mono/2.0/mscorlib.dll

The result of disassembly using the monodis tool shows the following information (guid uniquely identifies the file ):

.module mscorlib.dll // GUID = {F9EA90BC-5E97-4A29-A0A4-7F777CF93BC8} // Scala.NET
.module mscorlib.dll // GUID = {95A996E8-A93F-4388-A474-45EEDA546579} // mono 2.4.2.3 v1.0
.module mscorlib.dll // GUID = {9D069D60-9C3E-4912-90E1-B962D1A3C669} // mono 2.6.1 v1.0
.module mscorlib.dll // GUID = {32F1F939-70A3-452B-A8B7-FB4AB7284ACB} // mono 2.4.2.3 v2.0
.module mscorlib.dll // GUID = {7B63199A-BD44-405E-8C1F-EE5E2B4F2CA6} // mono 2.6.1 v2.0.0

These five mscorlib. dll can be divided into the following two groups (the first three belong to one group, and the last two belong to another group ):

mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The details of the two groups are shown in the following table:

Item Monoversion . Ver Fxversion Fxfileversion Vsversion Vsfileversion
Scala. net 1.9.1.0 1: 0: 5000: 0 1.0.5000.0 1.1.4322.2032 7.0.5000.0 7.10.6001.4
2.4.2.3 V1.0 2.4.2.3 1: 0: 5000: 0 1.0.5000.0 1.1.4322.2032 7.0.5000.0 7.10.6001.4
2.6.1 V1.0 2.6.1 1: 0: 5000: 0 1.0.5000.0 1.1.4322.2032 7.0.5000.0 7.10.6001.4
2.4.2.3 V2.0 2.4.2.3 2: 0: 0: 0 2.0.0.0 2.0.50727.1433 8.0.0.0 8.0.50727.1433
2.6.1 V2.0 2.6.1 2: 0: 0: 0 2.0.0.0 2.0.50727.1433 8.0.0.0 8.0.50727.1433

 

Next, let's take a look at the predef. Il and scalaruntime. Il compiled by monodis:

 

We can see that:

  • Predef depends on mscorlib 1: 0: 5000: 0 and scalaruntime 0: 0: 0: 0
  • Scalaruntime depends on mscorlib 2: 0: 0: 0

As Zhao said, this is confusing.

 

Now let's write a Complex C # program thexmltree. CS:

Using system; using system. LINQ; using system. XML. LINQ; namespace skyiv {public static class thexmltree {public static xelement getvalue () {var v = new xelement ("", new xelement ("Tian boguang", 3 ), new xelement ("Ling Hu Chong", 1), new xelement ("Yue Bu Qun", 4), new xelement ("Yi Lin", 2), new xelement ("Lin ping zhi ", 6), new xelement ("Ren Ying", 5); return New xelement ("Xiao AO Jianghu", from El in v. elements () Where (INT) El >=2 & (INT) El <= 5 select El );}}}

Then add a call to this class in the DOTNET. Scala program, as shown below:

Import system. leleobject DOTNET extends application {console. writeline ("Scala. net: Welcome to "); console. writeline ("OS version:" + environment. osversion); console. writeline ("CLR version: {0} ({1})", environment. version, skyiv. runtimeframework. currentframework); console. writeline ("default encoding:" + system. text. encoding. default); console. writeline (); console. writeline (skyiv. thexmltree. getvalue ());}

Finally, modify the MAKEFILE file as follows:

 

After all the modifications are completed, start generating the target program:

Ben @ Ben-vbox :~ /Projects/scalanet $Make
CSC-out: runtimeframework. dll-T: Library runtimeframework. CS
CSC-out: thexmltree. dll-T: Library-R: system. xml. LINQ. dll thexmltree. CS
/Opt/scala-2.7.7.final/bin/scalac-net-xassem-path runtimeframework. dll: thexmltree. dll DOTNET. Scala
8 @ (06 15 12 1D 02 12 11 02)
Error: Error while loading thexmltree, type 'skyiv. thexmltree' is broken
(15 @ 2 in (06 15 12 1D 02 12 11 02 ))
DOTNET. scala: 9: Error: Value getvalue is not a member of object skyiv. thexmltree
Console. writeline (skyiv. thexmltree. getvalue ());
^
Two errors found
Make: *** [DOTNET. msil] Error 1
Ben @ Ben-vbox :~ /Projects/scalanet $

Unfortunately, an error occurred while using scalac-net to convert the DOTNET. Scala source program to the DOTNET. msil Microsoft intermediate language.

The error message is: Type 'skyiv. thexmltree' is broken.

This should be caused by predef. dll dependency on the lower version of mscorlib 1: 0: 5000: 0.

The best solution is that Scala-msil authors use mscorlib 2: 0: 0: 0.

I am trying to modify predef. il. ver 1: 0: 5000: 0 changed. ver 2: 0: 0: 0, and then use ilasm for assembly. An error occurred while compiling the result.

So far today. If you can find a solution later, let's talk about it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.