Embedding boo in C#, does not recognise executing assembly
Asked Answered
S

2

7

scripts/ai/Dream.boo

import CultLib
import LonelyHero

class Dream(Enemy):
    pass

C#

var bc = new BooCompiler();
bc.Parameters.Input.Add(new FileInput("rsc/script/ai/" + "Dream" + ".boo"));
bc.Parameters.Pipeline = new CompileToMemory();
bc.Parameters.References.Add(Assembly.GetExecutingAssembly());
bc.Parameters.References.Add(Assembly.LoadFile(new DirectoryInfo("CultLib.dll").FullName));
bc.Parameters.References.Add(Assembly.LoadFile(new DirectoryInfo("sfmlnet-audio-2.dll").FullName));
bc.Parameters.References.Add(Assembly.LoadFile(new DirectoryInfo("sfmlnet-graphics-2.dll").FullName));
bc.Parameters.References.Add(Assembly.LoadFile(new DirectoryInfo("sfmlnet-window-2.dll").FullName));

var cc = bc.Run();

if(cc.GeneratedAssembly!=null)
{
    cc.GeneratedAssembly.CreateInstance("Dream", true, BindingFlags.NonPublic, null,
                                        new object[] {Parent, pos}, null, null);
}
else
{
    foreach (var error in cc.Errors)
        Console.WriteLine(error);
}

In the line bc.Parameters.References.Add(Assembly.GetExecutingAssembly()); I add the executing assembly, which contains the namespace "LonelyHero". However, the error

rsc/script/ai/Dream.boo(2, 8): BCE0021: Namespace LonelyHero not found. maybe you forgot to add an assembly reference?

appears.

LonelyHero should exist, why does this error occur and what can I do to resolve it?

Note: Upon replacing Assembly.GetExecutingAssmebly() with Assembly.GetAssembly(typeof(Enemy)) , thus assuring it adds the assembly with a class under the LonelyHero namespace, the same error occurs. Also with Assembly.LoadFile(new DirectoryInfo("LonelyHero.exe").FullName)

Occurs in Boo 0.9.4.9 and booxw-1203

Steve answered 19/12, 2012 at 5:32 Comment(4)
Could you provide a link with all relevant files? Also, where is the lonely hero assembly in the boo program? I see you importing it, but I don't see the code(or stubs of the code would do)Haemoglobin
LonelyHero.Enemy is a class that should be imported, if I understand what you ask.Steve
Is Enemy public? The imported namespace needs at least one public type.Corr
That was the issue, thanks! (Go ahead and post it as an answer so I can reward the bounty)Steve
C
3

Imported namespaces in BOO need to contain at least one public type for the import to succeed; otherwise you will get the BCE0021 error, so you want to make sure the Enemy type is public (or another one).

Corr answered 2/1, 2013 at 10:38 Comment(0)
M
1

I don't know Boo or C# but I found someone asking a similar question on the Boo Programming Google Group. The question they were asking:

"Namespace 'Pathfinding' not found, maybe you forgot to add an assembly reference?"

Specifically they were getting this error:

I am converting some existing code I had from C# into Boo. One of my classes had a "using Pathfinding" which got converted to "import Pathfinding" by the script converter.

I get this error when trying to compile:

Assets/Script/VehicleController.boo(4,8): BCE0021: Namespace 'Pathfinding' not found, maybe you forgot to add an assembly reference?

The Pathfinding library I'm using is written in C#. Could this cause problems? Is there anything additional I need to do to make this work?

This looked like your error message and the solution someone mentioned was that you needed to put your scripts into your compilation phase earlier to ensure that they're accessible from scripts written in other languages.

This URL was cited as a reference/source for more information on script compilation.

Mayest answered 1/1, 2013 at 14:58 Comment(3)
This solution is only relevant in Unity3D, I'm using VS12 and SFML.Steve
OK Thanks, thought I'd try for the +50 bounty, after I posted my solution I saw Simon's comment asking if Enemy was public.Mayest
I think I was drunk when I offered the bounty because I'd already switched from Boo to IronPython. Oh well, it was worth switching back.Steve

© 2022 - 2024 — McMap. All rights reserved.