473,836 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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( 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.
Nov 15 '05 #1
2 2387
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.co m

"Zach Mortensen" <zm********@hot mail.com> wrote in message
news:c9******** *************** ***@posting.goo gle.com...
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.

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.Attribut e
rather than my custom attribute. Please see the example JScript code
that I posted earlier.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:<uX******* *******@tk2msft ngp13.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
2313
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 executes code that is in our home page for the site. The only reason I know that is happening is because I keep track of the pages executed by the user to see how they have traversed the site. Has anyone every seen anything like this before? Regards, Aaron Prohaska
1
2528
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 (now table columns) as text in a Label object. Amazingly I have managed to display the table - no problem, I can select rows - no problem, BUT I can't work out how to display more than one of the fields (now columns in the table in the web page). I can display one field OK, but not more than one...
9
2827
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 queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
5
3051
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 are barring cookies (especially AOL users). If I change the setting in web.config everything seems to work fine as long as I'm using relative paths. The problem is I've got a menuing system that's generated from a site-wide template - so I use a fixed path from the application root - (ie:...
3
2168
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 "http://localhost/mysite", it works fine. Incidentally, I have "mysite" set up as a web application. Now when I test it going through "http://mysite/no-ip.org" then the toolbar doesn't work properly. It seems to merely render the images and any subsequent embedded Javascript but there are no events fired to the...
4
1233
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". The same site on my local server works just fine. When I change the "global.ascx" and ".dll" file in "bin" directory, it starts working fine but after some time, same problem arises again :(. Can any one help me plz in figuring out the problem, and I wud highly appreciate your suggestions and...
5
2738
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 ********************** <%@ Page Language="VB" Debug="true" %>
8
9771
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 drive resource (S:\Path\FileName). Here is my problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
13
3950
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 when i try to run the app from the .exe file that .NET creates i get the following error message: "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in VisioTimeline.exe
16
4934
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 says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10846
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10551
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10595
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.