473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Bug: handling value class events from another assembly

This has occurred in MC++, but since there is very little response on that
NG, I am also reporting it here in the hope that someone can find me a
workaround, and report it to MS.

If a __value class with an event is put into an assembly and a __gc class in
another assembly, which has an instance of the __value class as a data
member, attempts to attach its own event handler to the __value class's
event, everything compiles correctly but the Linker puts out error "LINK :
error LNK2020: unresolved token (0A000003) AValueClassEvent" followed by
"LINK : fatal
error LNK1120: 1 unresolved externals". If the __value class is in the same
assembly as the __gc class, everything is fine and there is no linker error.
What follows is code illustrating this bug.

------------------------------------------------------------------------

In one assembly:

// ValueClass.h
#pragma once
namespace ValueClass
{
public __value class AValueClass
{
public:
AValueClass();
__event System::EventHandler * AValueClassEvent;
int AnInt;
};
}

// ValueClass.cpp
#include "stdafx.h"
#include "ValueClass.h"
ValueClass::AValueClass::AValueClass() : AnInt(1) {}

In a second assembly which references the first assembly:

// HandleValueClassEvent.h
#pragma once
namespace HandleValueClassEvent
{
public __value class AnotherValueClass
{
public:
AnotherValueClass();
__event System::EventHandler * AnotherValueClassEvent;
int AnotherInt;
};
public __gc class HandleEvent
{
public:
HandleEvent();
void AMemberFunction();
void AnotherMemberFunction();
private:
ValueClass::AValueClass avc;
HandleValueClassEvent::AnotherValueClass anvc;
void AnEventHandler(System::Object *,System::EventArgs *);
};
}

// HandleValueClassEvent.cpp
#include "stdafx.h"
#include "HandleValueClassEvent.h"
HandleValueClassEvent::HandleEvent::HandleEvent() {}
void HandleValueClassEvent::HandleEvent::AMemberFunctio n()
{
avc.AValueClassEvent += new System::EventHandler(this,AnEventHandler);
}
void HandleValueClassEvent::HandleEvent::AnotherMemberF unction()
{
anvc.AnotherValueClassEvent += new
System::EventHandler(this,AnEventHandler);
}
void HandleValueClassEvent::HandleEvent::AnEventHandler (System::Object *
sender,System::EventArgs * e) {}
HandleValueClassEvent::AnotherValueClass::AnotherV alueClass() :
AnotherInt(1) {}

----------------------------------------------------------------------------
--

The attempt to add an event handler to avc.AValueClassEvent, which is in
another assembly, causes the linker error. If you comment it out there is no
error. The attempt to add an event handler to anvc.AnotherValueClassEvent,
which is the same assembly, causes no error.

Since I have designed a number of __value classes in an assembly which have
events which must be caught by __gc classes in other assemblies, I badly
need a workaround to this problem else I have to scrapped my own logical
design or duplicate value classes under slightly different names in each
assembly in which I want to use them, which is a real PITA.
Jul 21 '05 #1
5 2168
Edward Diener <ed******@tropicsoft.com> wrote:
This has occurred in MC++, but since there is very little response on that
NG, I am also reporting it here in the hope that someone can find me a
workaround, and report it to MS.


<snip>

Eek. Unfortunately I'm far from familiar with MC++. It looks like a
bug, certainly, but I'm not sure why.

If the class with the event is a __gc class, does it work? (Not trying
to find a solution here, just the boundaries of a problem.) I would
imagine it does, because otherwise all the events in Windows Forms
would fail.

Have you looked at the assembly containing the event with ildasm? It
might be instructive to see what it's got in it...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Jon Skeet [C# MVP] wrote:
Edward Diener <ed******@tropicsoft.com> wrote:
This has occurred in MC++, but since there is very little response
on that NG, I am also reporting it here in the hope that someone can
find me a workaround, and report it to MS.
<snip>


You found it.

Eek. Unfortunately I'm far from familiar with MC++. It looks like a
bug, certainly, but I'm not sure why.

If the class with the event is a __gc class, does it work?
Yes, of course.
(Not trying
to find a solution here, just the boundaries of a problem.) I would
imagine it does, because otherwise all the events in Windows Forms
would fail.
Yes,

Have you looked at the assembly containing the event with ildasm? It
might be instructive to see what it's got in it...


I will look at it.
Jul 21 '05 #3
Edward Diener <ed******@tropicsoft.com> wrote:
<snip>


You found it.


Yup :)
Have you looked at the assembly containing the event with ildasm? It
might be instructive to see what it's got in it...


I will look at it.


I'll try converting your code into C# and see whether it works then.
The next step (if it does) is to see whether your C++ calling code
links against my C# DLL, and then if my C# calling code works against
your C++ DLL, if you see what I mean.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
Jon Skeet [C# MVP] wrote:
Edward Diener <ed******@tropicsoft.com> wrote:
<snip>


You found it.


Yup :)
Have you looked at the assembly containing the event with ildasm? It
might be instructive to see what it's got in it...


I will look at it.


I'll try converting your code into C# and see whether it works then.
The next step (if it does) is to see whether your C++ calling code
links against my C# DLL, and then if my C# calling code works against
your C++ DLL, if you see what I mean.


I know C# also so I can try it myself. I have just been lazy. I will try to
narrow down in what intra-language situations it is occurring. It obviously
still needs to be reported to MS, and I will need to try to find a congenial
workaround for the problem.

I would be really surprised if I am the first to encounter it. A very common
idiom in my RAD programming is to have a component with an embedded __value
class in it as a property. When the component's properties get shown at
design time, the embedded __value class's properties also get expanded. In
this way one can group a component's properties into sub-components,
although a __value class is really not a component. In order for the
component to track the changes to the embedded __value class's properties, I
add events to the __value class for which the component adds handlers, in
order for the component to know when one of the embedded properties
changes.

Perhaps I am the only .NET programmer using the common idiom above who has
ever put their __value classes in one assembly and their components using
the __value classes in another assembly. Yet again this is very common when
the __value classes are shared by more than one assembly. So it is odd that
no one would have found this bug before.

The workaround in this case, of course, is to duplicate the __value classes
under a slightly different name in each assembly. That is a pretty awful
kludge of a clean design. I am really hoping to avoid that.
Jul 21 '05 #5
Jon Skeet [C# MVP] wrote:
Edward Diener <ed******@tropicsoft.com> wrote:
<snip>


You found it.


Yup :)
Have you looked at the assembly containing the event with ildasm? It
might be instructive to see what it's got in it...


I will look at it.


I'll try converting your code into C# and see whether it works then.
The next step (if it does) is to see whether your C++ calling code
links against my C# DLL, and then if my C# calling code works against
your C++ DLL, if you see what I mean.


I have investigated this bug and here is what I found:

1) Whether one creates the assembly, with the value class having an event,
in C++ or C# the testing result is the same. The one thing I noticed that
was different in the generated assembly, using .NET Reflector, is that the
C++ version generates a raise_AValueClassEvent while the C# version does
not. Still one can trigger the value class event from within either assembly
without any errors.

2) If one creates another assembly in C#, which embeds the value class in
the first assembly and hooks up an event handler to the event in the value
class, there are no linker error, whether one uses the C++ or C# version of
the first assembly.

3) If one creates another assembly in C+, which embeds the value class in
the first assembly and hooks up an event handler to the event in the value
class, the linker error occurs whether one uses the C++ or C# version of the
first assembly.

I have a solution which shows all this pretty obviously. I will report this
to MS by phone on Monday or Tuesday to see if I can get a decent workaround.
I will also report the minor enumeration bug which I found using C++ (
enumeration in one assembly, when referred to in another assembly, needs
full name with enumeration name and not just enumerated value ).

I do wish that MS would put out fixes to VS .NET problems and not wait until
Whidbey and saddle programmers with another full year at least of
workarounds to bugs, such as this one. The arrogance of their refusal to
consider service packs for VS .NET is awful. It was bad enough when Borland
refused to fix bugs in BCB with a sort of demented obstinancy, but when MS,
who had been consistent in providing bug fixes to their previous VS6
product, does it, it is even worse. Despite what they think, programmers
will remember the way they have been treated by large corporations.
Jul 21 '05 #6

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

Similar topics

0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
19
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
3
by: Fett | last post by:
Problem: My member variables in the child class are always null. I don't know why this happens! I have a base class for handling a user flow in my web, CWebUseCase, the class is declared like:...
0
by: Edward Diener | last post by:
If a __value class with an event is put into an assembly, and a __gc class in another assembly attempts to attach its own event handler to the __value class's event of an embedded object of the...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
10
by: Edward Diener | last post by:
This has occurred in MC++, but since there is very little response on that NG, I am also reporting it here in the hope that someone can find me a workaround, and report it to MS. If a __value...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.