472,353 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Problem Using C#-defined Custom Attributes in JScript.NET

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.
Nov 15 '05 #1
2 2294
Zach,

Are you sure that you are setting a reference to the assembly that
contains the attribute correctly? It seems like this could be it to me. If
not, then are you sure that the namespace resolution is working correctly
(some sort of using statement for JS that you are forgetting, so that it
isn't finding it?).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zach Mortensen" <zm********@hotmail.com> wrote in message
news:c9**************************@posting.google.c om...
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.

Nov 15 '05 #2
Thanks for the reply. I am sure that all of the assembly-references
and using-statements are correct because I can derive a JScript class
from a C# class that is defined in the same assembly as the C#-defined
custom attribute that causes the problem, and if I omit the attributes
from the JScript code, the code compiles properly. The code also
compiles if I change the attribute so that it extends System.Attribute
rather than my custom attribute. Please see the example JScript code
that I posted earlier.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<uX**************@tk2msftngp13.phx.gbl>...
Zach,

Are you sure that you are setting a reference to the assembly that
contains the attribute correctly? It seems like this could be it to me. If
not, then are you sure that the namespace resolution is working correctly
(some sort of using statement for JS that you are forgetting, so that it
isn't finding it?).

Hope this helps.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow...
1
by: Joe Bloggs | last post by:
I am trying display the contents of a table in a web page, select certain rows from that table and then display the fields that I have selected...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my...
5
by: | last post by:
Hi, I'm trying to use the cookie munging session handling behaviour of asp.net instead of cookies themselves as I'm finding quite a few people...
3
by: Microsoft Newsgroups | last post by:
Hi all, I'm having an interesting problem with my IE Webcontrols. I'm using the toolbar and when I test it in my browser using...
4
by: zubair | last post by:
Hello everyone! I have uploaded my site on a webserver. Some times it works fine but some time it gives error "Null Object reference exception"....
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.