Method not found: 'Int32 System.Runtime.InteropServices.Marshal.SizeOf(!!0)

1,245 views
Skip to first unread message

Robert Carrington

unread,
Sep 30, 2014, 9:03:43 AM9/30/14
to cs-s...@googlegroups.com
I'm getting a Method not found: 'Int32 System.Runtime.InteropServices.Marshal.SizeOf(!!0)'. error when calling CSScript.LoadCode(String scriptText, String[] refAssemblies) when running my application on a Windows Server 2008 R2 Standard machine with .net 4.5 installed.  If I run the same code on my Windows 7 .net 4.5.1 machine it works fine.  I'm using CS-Script v3.7 (via NuGet).  I found the following article: https://csscriptnpp.codeplex.com/wikipage?title=FAQ that gives a possible cause for the issue, however as far as I can tell I'm using the latest version and would never have used a version that was old enough to be a problem.  Does CS-Script require 4.5.1 now?  Is it possible this is caused by my script referencing something that requires 4.5.1 (I don't think it is)?

full error:

Method not found: 'Int32 System.Runtime.InteropServices.Marshal.SizeOf(!!0)'.
   at csscript.MetaDataItems..ctor()
   at csscript.CSExecutor.ProcessCompilingResult(CompilerResults results, CompilerParameters compilerParams, ScriptParser parser, String scriptFileName, String assemblyFileName, String[] additionalDependencies)
   at csscript.CSExecutor.Compile(String scriptFileName)
   at csscript.CSExecutor.Compile(String scriptFile, String assemblyFile, Boolean debugBuild)
   at CSScriptLibrary.CSScript.LoadWithConfig(String scriptFile, String assemblyFile, Boolean debugBuild, Settings scriptSettings, String compilerOptions, String[] refAssemblies)
   at CSScriptLibrary.CSScript.Load(String scriptFile, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String tempFileExtension, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String[] refAssemblies)

Oleg Shilo

unread,
Sep 30, 2014, 2:34:59 PM9/30/14
to cs-s...@googlegroups.com
The problem was caused by undesired (and accidental) compiler optimization of the binaries for that specific release. Please get the latest release from NuGet or from CodePlex. This should solve your problem.

Cheers,
Oleg

Robert Carrington

unread,
Oct 1, 2014, 4:18:27 AM10/1/14
to cs-s...@googlegroups.com
I'm not sure what was going on with this.  As far as I can tell I was always on the latest release and had never had the bad release, however today everything is working fine on both machines so something happened - probably some stupid mistake on my part.  Sorry for wasting your time.

--
You received this message because you are subscribed to a topic in the Google Groups "CS-Script" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cs-script/eQ6kPBWvDEI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cs-script+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleg Shilo

unread,
Oct 1, 2014, 4:22:15 AM10/1/14
to cs-s...@googlegroups.com
Not a problem. None was wasted. 
Have a good day,
Oleg

--
You received this message because you are subscribed to the Google Groups "CS-Script" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cs-script+...@googlegroups.com.

Robert Carrington

unread,
Oct 1, 2014, 6:04:27 AM10/1/14
to cs-s...@googlegroups.com
I've just managed to reproduce it again and I'm definitely use v3.7 (via NuGet).  For most functions it works but the following code fails:
string scriptText = @"using System; class Script { public static Func<dynamic, bool> GetFunc() { return e => e.EventType == \"test\"; } }";
AsmHelper script = new AsmHelper(CSScript.LoadCode(scriptText)); // throws Method not found exception
Func<dynamic, bool> result = script.Invoke("Script.GetFunc") as Func<dynamic, bool>;

The full exception is:
Method not found: 'Int32 System.Runtime.InteropServices.Marshal.SizeOf(!!0)'.
   at csscript.MetaDataItems..ctor()
   at csscript.CSExecutor.ProcessCompilingResult(CompilerResults results, CompilerParameters compilerParams, ScriptParser parser, String scriptFileName, String assemblyFileName, String[] additionalDependencies)
   at csscript.CSExecutor.Compile(String scriptFileName)
   at csscript.CSExecutor.Compile(String scriptFile, String assemblyFile, Boolean debugBuild)
   at CSScriptLibrary.CSScript.LoadWithConfig(String scriptFile, String assemblyFile, Boolean debugBuild, Settings scriptSettings, String compilerOptions, String[] refAssemblies)
   at CSScriptLibrary.CSScript.Load(String scriptFile, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String tempFileExtension, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String assemblyFile, Boolean debugBuild, String[] refAssemblies)
   at CSScriptLibrary.CSScript.LoadCode(String scriptText, String[] refAssemblies)

Oleg Shilo

unread,
Oct 1, 2014, 7:10:39 AM10/1/14
to cs-s...@googlegroups.com
But this is exactly the problem. The latest NuGet version is v3.8.8 not v3.78
Inline image 1

Robert Carrington

unread,
Oct 1, 2014, 7:22:15 AM10/1/14
to cs-s...@googlegroups.com
bah! I guess I need to learn to use nuget.  I could have sworn I visited that page yesterday and ran Update-Package and it still showed 3.7.  Ran it now and it's updated properly.  I'm questioning my sanity right now!

I also just realised I could do exactly what I wanted using CSScript.Evaluator.LoadDelegate<T>() anyway and that bypassed the problem too.

Thanks again,
Rob

On 1 October 2014 12:10, Oleg Shilo <oleg....@gmail.com> wrote:
But this is exactly the problem. The latest NuGet version is v3.8.8 not v3.78
Inline image 1

Oleg Shilo

unread,
Oct 1, 2014, 7:42:15 AM10/1/14
to cs-s...@googlegroups.com
Ha-ha... we all have these moments :o)
Reply all
Reply to author
Forward
0 new messages