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;
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.
[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()
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.
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.
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.
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…
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.