简体   繁体   English

在C#中嵌入boo,无法识别正在执行的程序集

[英]Embedding boo in C#, does not recognise executing assembly

scripts/ai/Dream.boo 脚本/ AI / Dream.boo

import CultLib
import LonelyHero

class Dream(Enemy):
    pass

C# 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()); 在行bc.Parameters.References.Add(Assembly.GetExecutingAssembly()); I add the executing assembly, which contains the namespace "LonelyHero". 我添加了执行程序集,其中包含命名空间“LonelyHero”。 However, the error 但是,错误

rsc/script/ai/Dream.boo(2, 8): BCE0021: Namespace LonelyHero not found. rsc / script / ai / Dream.boo(2,8):BCE0021:未找到命名空间LonelyHero。 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? LonelyHero应该存在,为什么会出现此错误,我该怎么做才能解决它?

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. 注意:在使用Assembly.GetAssembly(typeof(Enemy))替换Assembly.GetExecutingAssmebly()时,从而确保它在LonelyHero命名空间下添加了一个类,同样的错误也会发生。 Also with Assembly.LoadFile(new DirectoryInfo("LonelyHero.exe").FullName) 还有Assembly.LoadFile(new DirectoryInfo("LonelyHero.exe").FullName)

Occurs in Boo 0.9.4.9 and booxw-1203 发生在Boo 0.9.4.9和booxw-1203中

Imported namespaces in BOO need to contain at least one public type for the import to succeed; BOO中导入的命名空间需要包含至少一个公共类型才能使导入成功; otherwise you will get the BCE0021 error, so you want to make sure the Enemy type is public (or another one). 否则你会得到BCE0021错误,因此你想确保Enemy类型是公共的(或另一个)。

I don't know Boo or C# but I found someone asking a similar question on the Boo Programming Google Group. 我不知道Boo或C#,但我发现有人在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. 我正在将一些现有的代码从C#转换为Boo。 One of my classes had a "using Pathfinding" which got converted to "import Pathfinding" by the script converter. 我的一个类有一个“使用Pathfinding”,它被脚本转换器转换为“import Pathfinding”。

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? Assets / Script / VehicleController.boo(4,8):BCE0021:找不到命名空间'寻路',也许你忘了添加汇编参考?

The Pathfinding library I'm using is written in C#. 我正在使用的Pathfinding库是用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. URL被引用作为有关脚本编译的更多信息的参考/来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM