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( AttributeTarget s.All)]
public abstract class MyCsharpAttribu te : Attribute
{
}
[AttributeUsage( AttributeTarget s.Class)]
public class MyCsharpClassAt tribute : MyCsharpAttribu te
{
}
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 MyCsharpClassAt tribute.
public class MyJsClass extends MyNamespace.MyC sClass {
}
public AttributeUsage( AttributeTarget s.Class) class
MyJscriptClassA ttribute extends MyNamespace.MyC sharpClassAttri bute {
public function MyJscriptClassA ttribute(name) {
}
}
public MyJscriptClassA ttribute("Hello , world.")
class MyOtherJsClass extends MyNamespace.MyC sClass {
}
Note that I get the same error when I use the MyCsharpClassAt tribute
directly in place of MyJscriptClassA ttribute. I also get the same
error if MyJscriptClassA ttribute extends MyCsharpAttribu te instead of
MyCsharpClassAt tribute.
Here's the catch: if I change MyJscriptClassA ttribute so that it
extends Attribute instead of MyCsharpClassAt tribute (i.e. remove C#
attributes from the equation and define the MyJscriptClassA ttribute
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.
C#-defined custom attributes. I have a simple attribute and a class
defined in a C# assembly:
namespace MyNamespace
{
[AttributeUsage( AttributeTarget s.All)]
public abstract class MyCsharpAttribu te : Attribute
{
}
[AttributeUsage( AttributeTarget s.Class)]
public class MyCsharpClassAt tribute : MyCsharpAttribu te
{
}
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 MyCsharpClassAt tribute.
public class MyJsClass extends MyNamespace.MyC sClass {
}
public AttributeUsage( AttributeTarget s.Class) class
MyJscriptClassA ttribute extends MyNamespace.MyC sharpClassAttri bute {
public function MyJscriptClassA ttribute(name) {
}
}
public MyJscriptClassA ttribute("Hello , world.")
class MyOtherJsClass extends MyNamespace.MyC sClass {
}
Note that I get the same error when I use the MyCsharpClassAt tribute
directly in place of MyJscriptClassA ttribute. I also get the same
error if MyJscriptClassA ttribute extends MyCsharpAttribu te instead of
MyCsharpClassAt tribute.
Here's the catch: if I change MyJscriptClassA ttribute so that it
extends Attribute instead of MyCsharpClassAt tribute (i.e. remove C#
attributes from the equation and define the MyJscriptClassA ttribute
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.
Comment