I can't seem to get dynamically-compiled JScript code to use
C#-defined custom attributes. I have a simple attribute and a class
defined in a C# assembly:
namespace MyNamespace
{
[AttributeUsage(AttributeTargets.All)]
public abstract class MyCsharpAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class)]
public class MyCsharpClassAttribute : MyCsharpAttribute
{
}
public class MyCsClass
{
}
}
Needless to say, I have many, many C# classes that use these
attributes without any problem whatsoever.
I also have some dynamically-compiled JScript.NET code (called from
C#) that needs to use these attributes. Whenever I attempt to use the
attributes within the JScript.NET, the JScript does not compile. I
receive the error "Unknown custom attribute class or constructor"
// This class compiles properly, there is no problem referencing the
assembly
// that contains MyCsharpClass and MyCsharpClassAttribute.
public class MyJsClass extends MyNamespace.MyCsClass {
}
public AttributeUsage(AttributeTargets.Class) class
MyJscriptClassAttribute extends MyNamespace.MyCsharpClassAttribute {
public function MyJscriptClassAttribute(name) {
}
}
public MyJscriptClassAttribute("Hello, world.")
class MyOtherJsClass extends MyNamespace.MyCsClass {
}
Note that I get the same error when I use the MyCsharpClassAttribute
directly in place of MyJscriptClassAttribute. I also get the same
error if MyJscriptClassAttribute extends MyCsharpAttribute instead of
MyCsharpClassAttribute.
Here's the catch: if I change MyJscriptClassAttribute so that it
extends Attribute instead of MyCsharpClassAttribute (i.e. remove C#
attributes from the equation and define the MyJscriptClassAttribute
strictly in JScript), the JScript.NET code compiles properly!
Can anyone shed any light on this problem? At this point, I think it
must be a problem with the JScript.NET compiler. Thanks in advance.