CodeDomProvider CompiledAssembly is null in 11.0.0.2791

The following UnitTest now fails in 11.0.0.2791 with

Test method ToolboxUnitTest.CompileTest.SimpleCompileTest threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

results.CompiledAssembly is null in results.CompiledAssembly.GetType(“Toolbox.Code.__Global”);

    [TestMethod]
    public void SimpleCompileTest()
    {
        var provider = CodeDomProvider.CreateProvider("Oxygene");
        var results = provider.CompileAssemblyFromSource(new CompilerParameters(), StringCode);

        if (results.Errors.HasErrors) Console.WriteLine(FormattedErrors(results.Errors));
        Assert.IsFalse(results.Errors.HasErrors);
        var testCode = results.CompiledAssembly.GetType("Toolbox.Code.__Global");
        var testFunc = testCode.GetMethod("myLength");
        var result = testFunc?.Invoke(null, new object[] {"abcd"});
        Assert.AreEqual((int) result, 4);
    }

where StringCode is defined as:

    private const string StringCode = @"

namespace Toolbox.Code;

interface

uses
System,
System.Text;

{$GLOBALS ON}

function myLength(src: String): Integer; public;

{$GLOBALS DEFAULT}

implementation

function myLength(src: String): Integer;
begin
result := src.Length;
end;

end.
";

The value of results is:

results
{System.CodeDom.Compiler.CompilerResults}
    CompiledAssembly: null
    Errors: {System.CodeDom.Compiler.CompilerErrorCollection}
    Evidence: null
    NativeCompilerReturnValue: 1
    Output: {System.Collections.Specialized.StringCollection}
    PathToAssembly: null
    TempFiles: {System.CodeDom.Compiler.TempFileCollection}
results.Errors
{System.CodeDom.Compiler.CompilerErrorCollection}
    Capacity: 0
    Count: 0
    HasErrors: false
    HasWarnings: false
    InnerList: Count = 0
    List: {System.CodeDom.Compiler.CompilerErrorCollection}
    Results View: Expanding the Results View will enumerate the IEnumerable

I now see that NativeCompilerReturnValue is 1 (used to be 0). But I have no idea, how to get more info from CodeDom.

This used to work for years now but I can’t say for sure when broke, as we hardly ever touch this area anymore.

in Version 11.0.0.2777 it worked:

results
{System.CodeDom.Compiler.CompilerResults}
    CompiledAssembly: {xs234ohu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    Errors: {System.CodeDom.Compiler.CompilerErrorCollection}
    Evidence: null
    NativeCompilerReturnValue: 0
    Output: {System.Collections.Specialized.StringCollection}
    PathToAssembly: "....\\AppData\\Local\\Temp\\1\\xs234ohu.dll"
    TempFiles: {System.CodeDom.Compiler.TempFileCollection}
results.Errors
{System.CodeDom.Compiler.CompilerErrorCollection}
    Capacity: 0
    Count: 0
    HasErrors: false
    HasWarnings: false
    InnerList: Count = 0
    List: {System.CodeDom.Compiler.CompilerErrorCollection}
    Results View: Expanding the Results View will enumerate the IEnumerable

NativeCompilerReturnValue is 0

I agree, our code should check NativeCompilerReturnValue for 0, but the problem remains :wink:

I believe we had a regression with registering coded a few weeks back that should be fixed in latest. Though I would have thought that fixed primer to .2791, which is only two weeks old — ut I could be mistaken.

Can you install .2795?

Sure, will check tomorrow.

With .2795: same result.

I added a test for NativeCompilerReturnValue:

        [TestMethod]
        public void SimpleCompileTest()
        {
            var provider = CodeDomProvider.CreateProvider("Oxygene");
            var results = provider.CompileAssemblyFromSource(new CompilerParameters(), StringCode);

            Assert.AreEqual(0, results.NativeCompilerReturnValue);
            if (results.Errors.HasErrors) Console.WriteLine(FormattedErrors(results.Errors));
            Assert.IsFalse(results.Errors.HasErrors);

            var testCode = results.CompiledAssembly.GetType("Toolbox.Code.__Global");
            var testFunc = testCode.GetMethod("myLength");
            var result = testFunc?.Invoke(null, new object[] {"abcd"});
            Assert.AreEqual((int) result, 4);
        }

and it now fails at Assert.AreEqual(0, results.NativeCompilerReturnValue); with

Assert.AreEqual failed. Expected:<0>. Actual:<1>. 
   at ToolboxUnitTest.CompileTest.SimpleCompileTest()

is Oxygene in your machine.config? when you run

ElementsHelper.exe --installcodedom

whats the output? thats the tool, run on setup, that registeres the codedom. Also, what version of .NET is this?

RemObjects Elements CodeDom Installer

RemObjects Elements Version is 11.0.0.2795
Processing C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config
Found Chrome entry, updating.
Found Oxygene entry, updating.
Found Hydrogene entry, updating.
Found Silver entry, updating.
Found Iodine entry, updating.
Found Mercury entry, updating.

It’s .NET 4.8

I found something else, it’s not that CodeDom is not working at all.
It seems to works, as soon as I add any ReferencedAssemblies to the CompilerParameters.

Curious.

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config

is the file for .NET 2.x, it seems its not finding/updating the ones for v3.5+. Let me have quick look at the logic…

Hmm. I see why it would only update the 3.5 one but not the one for 4.0 because the tool is built for 3.5. But I don’t see why this would have changed, how it it could ever have worked.

I’ll change the tool to be built for 4.8, lets see if that fixes the issue for you, in 2797 today.

:thinking:

I dont understand. so does

var provider = CodeDomProvider.CreateProvider("Oxygene");

return a provider or nil? So this seems to not be about a missing CodeDom provider at all, then.

CompileAssemblyFromSource isn’t ours, thats provided by the core .NET runtime (and really unrelated to CodeDom). I’m not sure quite how this goes to invoke our compiler, but noting has changed in that area in forever, as far as I know.

That said, I would expect compiling anything to fail if you don’t have any ReferencedAssemblies, so that would just be as designed? (I’m not sure if/how CompileAssemblyFromSource is expected to provide any feedback as far as compiler error go…)

Provider is not null, results.NativeCompilerReturnValue is 1 after the call to CompileAssemblyFromSource.
No, this case really does not need any additional Assemblies. It works, as soon as I add any unused assembly.

And yes, it normally gives feedback in the ErrorList. NativeCompilerReturnValue == 1 means, something really aborted.

Hm ok. I’ll havoc check with Carlo on Monday then, a I’m not familiar with how this works. But as I said, nothing really has changed here in the past few weeks, so it seems odd that only three builds ago this worked and now it doesn’t…

No rush, Monday is fine :wink:
Sorry, but it’s not three weeks ago, it was .2777 when it worked, that must be older than three builds ago:

Hm, but that’s also not so old. Hm.

Yeah, sorry I misread. .2777 was built September 30. That said, I just skimmed the change log since then and I really can’t find anything that even remotely touches this :(, as the compile team has been focused nearly 100% on Island-specific stuff that lives very far away from this, the past few months…

I’ll hope Carlo will have an idea how this hooks in, and where to begin looking at what fails, next week.

1 Like

Any news in this area?

My apologies; i’ll chase this up with Carlo,

1 Like

Fixed. Manual workaround for now: explicitly reference mscorlib.dll.

1 Like

Confirmed: fixed in 11.0.0.2803

1 Like