Metadata file could not be found (Mono)

273 views
Skip to first unread message

Ricardo Fuente

unread,
Nov 7, 2017, 4:50:46 AM11/7/17
to CS-Script
Hi again Oleg,

I've come across some difficulties with CSScript after version 3.22.0 on Mono.
This is our scenario:
  • We use file scripts
  • We use CSScript legacy API
  • To sped up things, caching is enabled but we choose the folder for the compiled libraries
  • This is the line causing an exception: 
    CSScript.Load(file,compiledFullPath,false).CreateObject("Driver");
    where Driver, as you can surely assume, is the class defined inside the script file.
  • Our application is developed in a Windows/Visual Studio environment and, when needed, we deploy it in Linux with the help of Mono v4.6.2
CSScript latest available version in Nuget (3.27.2) does not work as expected when running through the aforementioned version of Mono. This is the exception message:
(0,0): error CS0006: Metadata file `/tmp/CSScript/Cache/-2029024245/22857.8097c69b-5cd3-4074-af74-de06af75cf2f.tmp.compiled.dll' could not be found

And this is the stack trace:

  at csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults results, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) [0x000fa] in <6af0d57b01bb4fe2a858e3e21399957c>:0 
  at csscript.CSExecutor.Compile (System.String scriptFileName) [0x0077a] in <6af0d57b01bb4fe2a858e3e21399957c>:0 
  at csscript.CSExecutor.Compile (System.String scriptFile, System.String assemblyFile, System.Boolean debugBuild) [0x00045] in <6af0d57b01bb4fe2a858e3e21399957c>:0 
  at CSScriptLibrary.CSScript.LoadWithConfig (System.String scriptFile, System.String assemblyFile, System.Boolean debugBuild, csscript.Settings scriptSettings, System.String compilerOptions, System.String[] refAssemblies) [0x00114] in <6af0d57b01bb4fe2a858e3e21399957c>:0 
  at CSScriptLibrary.CSScript.LoadFile (System.String scriptFile, System.String assemblyFile, System.Boolean debugBuild, System.String[] refAssemblies) [0x00000] in <6af0d57b01bb4fe2a858e3e21399957c>:0 
  at Overon.Solution.Engine.recompileDriver (System.String driverName) [0x0006a] in <35f9e778c479400f88c40f95a2eb1473>:0 

So, if I'm not mislead, CSScript is trying to find a previously compiled assembly at /tmp/ folder and maybe ignoring our compiledFullPath parameter? Do you have any idea why this is happening?

I haven't had the chance to try with every version up to 3.27.2 but I can assure it works on CSScript 3.22.0.
FYI: I've tried changing Load to LoadFile (as Load has been marked obsolete) with the same results.

Thanks in advance.
Ricardo.

Oleg Shilo

unread,
Nov 7, 2017, 6:54:39 PM11/7/17
to CS-Script
Hi Ricardo,

Just a few points for a start.

but we choose the folder for the compiled libraries
How exactly did you set the custom caching location? Is it via CSScript.LoadFile
 second parameter?

So, if I'm not mislead, CSScript is trying to find a previously compiled assembly at /tmp/ folder ...
Actually not.  
The error (CS0006: Metadata file ) is a C# compiler error. Meaning that also indicate that ...3-4074-af74-de06af75cf2f.tmp.compiled.dll was specified as a referenced assembly when the C# code pas passed for the compilation to the Mono C# compiler. Meaning that CS-Script is not trying to load the script from the default cache location but rather reference it for at least some scripts. 

As an idea... this may be an undesired result of CSScript.ShareHostRefAssemblies. But, it's just a guess.  

To be honest I cannot link the problem (at least right away) to the latest CS-Script features. Though one obvious suspect is Roslyn compiler that is compiling now your scripts on Linux. If it is the case then may be disabling Mono's Roslyn would be an option to try.  

Anyway, I logged on your behalf the issue on GitHub: https://github.com/oleg-shilo/cs-script/issues/92

Note, I also created a test project (attached to the issue) that shows that the feature works as expected on Linux (Mint 18.1). 

The best chances for this to be resolved is for you to get that test project and try to modify it so it triggers the problem you are experiencing. Then I will be able to truly investigate it.

Thank you,
Oleg

Ricardo Fuente

unread,
Nov 8, 2017, 6:42:11 AM11/8/17
to CS-Script
Hi Oleg, thanks again for your great support.
FYI: we are not using Roslyn compiler yet, in case you related this question with the previous one. We still have to evaluate if script loading performance is worth just to benefit from C# 6 and C#7 features.

I've tested your sample project, as is, and the same exception (see above) was thrown. Test environment is:
  • CentOS Linux release 7.3.1611
  • Mono JIT compiler versión 4.6.2
Please have a look at the attached snapshots.

But this gave me an idea, and tried ConsoleApp20 in another machine. The result was OK in:
  • Ubuntu 14.04 LTS
  • Mono JIT compiler version 5.0.0
And also OK in:
  • Debian 8 (jessie)
  • Mono JIT compiler version 5.4.0
I'm pretty sure it has to do with Mono version but haven't been able to test a 4-version outside a CentOS. Anyway, I wanted to share these results in case they're useful for you or any other CSScript user.
I'll post a summary on GitHub but I don't think this to be worth much of your time trying to figure out the exact cause.

Thanks,
CharacteristicsSnapshot.png
ExceptionSnapshot.png
OKSnapshot.png

Oleg Shilo

unread,
Nov 8, 2017, 11:12:55 PM11/8/17
to cs-s...@googlegroups.com
Just a few pointers:

> FYI: we are not using Roslyn compiler yet, in case you related this question with the previous one.
You may be using it without knowing about it. Mono comes with Roslyn (at least latest releases). You may use Legacy API but the compiler that compiles the C# code may in fact be Roslyn (csc.exe). 

Inline image 1

Another point is that exception:
Inline image 2

Did you try to execute the app while being elevated? May be it is just a permission issue?


Ricardo Fuente

unread,
Nov 10, 2017, 3:05:06 AM11/10/17
to CS-Script

We usually don't have the need to install cscs.exe and just deploy our application with CSScript.dll. I downloaded latest version to check what you pointed about the compiler and got this:



It just says <default> but I'm pretty sure you know much more than me about this ;)


Regarding your second note, you were right one more time: ConsoleApp20 ends successfully if executed as sudo. Maybe it's just a matter of O.S permissions.

Thanks a lot Oleg.


Oleg Shilo

unread,
Nov 10, 2017, 4:55:09 AM11/10/17
to cs-s...@googlegroups.com
Yes I was also using cscs as a test app to see if Roslyn can be located. Though in your case you probably just "downloaded latest version" and in this form (without CSSRoalynProvider.dll) cscs.exe does not attempt to locate Roslyn. Thus your "<default>" (means default, non-Roslyn C# compiler) is rather inconclusive.

If you want you can install CS-Script via a proper Debian package. You will find shell command here: https://github.com/oleg-shilo/cs-script/wiki/CS-Script-on-Linux
This installation will try to locate Roslyn at runtime.

Anyway I am glad "sudo" made the difference. Though it means that on some Linux distro the user-tempfolder (this is where Cs-script caching is) may have incompatible permissions. Meaning that on Linux I will need to do a special test and report the problem specifically. I will mark the GitHub issue and "enhancement".

Cheers,
Oleg

Ricardo Fuente

unread,
Nov 13, 2017, 2:36:22 AM11/13/17
to CS-Script
OK Oleg, thanks again for your support.
Message has been deleted

Ricardo Fuente

unread,
Feb 13, 2018, 7:27:28 AM2/13/18
to CS-Script
In case someone comes to this thread and experiences CS0006 compiler error is still happening although running under sudo or any other user with permission to write in /tmp/ ...

Versions of CSSCript above 3.22.0 running scripts (hosted) under mono, should also set
 CSScript.ShareHostRefAssemblies = false;
Reply all
Reply to author
Forward
0 new messages