473,327 Members | 1,967 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,327 software developers and data experts.

is operator is falsely failing

Bob
I have a Class3 that looks like this:
Class1 : BaseClass
Class2 : Class1
Class3 : Class2

where each of these classes are defined in their own projects/assemblies.
They are all built in the same solution with project references. I also have
a peice of code that looks this this:

System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFrom("Class3.dll");
Type assemblyType = assembly.GetType("Class3");
object class3 = Activator.CreateInstance(assemblyType);

if (class3 is Class3)
XXXX;

if (class3 is Class2)
YYYYY;

This code has worked for years and just broke after converting all of our
projects from using assembly references to using project references. The
first if statement fails and the XXXX code is not called. However, the
second if statement passes and the YYYY code is called. Why is this?
Looking in the debugger, the class3 object is a type Class3 , which is a
Class2, etc. Any hints on what I can look at to find this problem? Thanks?
Jul 21 '05 #1
8 1223
I believe it's because the Class3 type loaded from the DLL and the Class3
type created using project reference are not the same class even if they
have the same name.

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Bob" <rv@b.com> wrote in message
news:0D**********************************@microsof t.com...
I have a Class3 that looks like this:
Class1 : BaseClass
Class2 : Class1
Class3 : Class2

where each of these classes are defined in their own projects/assemblies.
They are all built in the same solution with project references. I also have a peice of code that looks this this:

System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFrom("Class3.dll");
Type assemblyType = assembly.GetType("Class3");
object class3 = Activator.CreateInstance(assemblyType);

if (class3 is Class3)
XXXX;

if (class3 is Class2)
YYYYY;

This code has worked for years and just broke after converting all of our
projects from using assembly references to using project references. The
first if statement fails and the XXXX code is not called. However, the
second if statement passes and the YYYY code is called. Why is this?
Looking in the debugger, the class3 object is a type Class3 , which is a
Class2, etc. Any hints on what I can look at to find this problem?

Thanks?
Jul 21 '05 #2
Bob
How can I tell if they are not the same? Is there a way to compare a
project's DLL output using ILDASM or something else?

All the DLLs in the solution are copied to a runtime folder and ran from
there. The copy is done on a post build event in the project.

"Shuvro Mazumder [MSFT]" wrote:
I believe it's because the Class3 type loaded from the DLL and the Class3
type created using project reference are not the same class even if they
have the same name.

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Bob" <rv@b.com> wrote in message
news:0D**********************************@microsof t.com...
I have a Class3 that looks like this:
Class1 : BaseClass
Class2 : Class1
Class3 : Class2

where each of these classes are defined in their own projects/assemblies.
They are all built in the same solution with project references. I also

have
a peice of code that looks this this:

System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFrom("Class3.dll");
Type assemblyType = assembly.GetType("Class3");
object class3 = Activator.CreateInstance(assemblyType);

if (class3 is Class3)
XXXX;

if (class3 is Class2)
YYYYY;

This code has worked for years and just broke after converting all of our
projects from using assembly references to using project references. The
first if statement fails and the XXXX code is not called. However, the
second if statement passes and the YYYY code is called. Why is this?
Looking in the debugger, the class3 object is a type Class3 , which is a
Class2, etc. Any hints on what I can look at to find this problem?

Thanks?

Jul 21 '05 #3
Bob... To back up. The runtime fully qualified name is actually the name
of
the assembly "pre-pended" to the class fully qualified name so that:

MyDLL1.MyNamespace.MyClass is distinct from
MyDLL2.MyNamespace.MyClass

http://www.geocities.com/jeff_louie/OOP/oop20.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #4
Bob
Well since my DLL name and the namespaces have not changed, this cannot be
the answer. Any other ideas?

"Jeff Louie" wrote:
Bob... To back up. The runtime fully qualified name is actually the name
of
the assembly "pre-pended" to the class fully qualified name so that:

MyDLL1.MyNamespace.MyClass is distinct from
MyDLL2.MyNamespace.MyClass

http://www.geocities.com/jeff_louie/OOP/oop20.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #5
I still think that Shuvro may be right. I suspect that Class C in
MyDll.ClassC is
not assignable from MyProject.ClassC.

string typeName="MyDLL.ClassC,MyDLL";
Type myType= Type.GetType(typeName);

if (typeof(ClassC).IsAssignableFrom(myType)) --> false

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #6
Bob <rv@b.com> wrote:
Well since my DLL name and the namespaces have not changed, this cannot be
the answer. Any other ideas?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7
Bob
I just found the solution for the problem.

I falsly reported in an earlier post that "All the DLLs in the solution are
copied to a runtime folder and ran from there. The copy is done on a post
build event in the project." I was not running from the runtime folder. If
I ran the app from the runtime folder by double clicking the exe, it worked.
If I ran from Visual Studio, it did not work. I changed the Debugging -
"Debug Mode" Property from Project to Program and entered in the exe path for
"Start Application". That fixed the problem. With the property set to
Project, the exe was running from the local bin\debug folder and the DLLs
were loaded from the runtime folder.

Could some please explain why this behavior? Is this a security issue?
"Jon Skeet [C# MVP]" wrote:
Bob <rv@b.com> wrote:
Well since my DLL name and the namespaces have not changed, this cannot be
the answer. Any other ideas?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #8
Bob <rv@b.com> wrote:
I just found the solution for the problem.

I falsly reported in an earlier post that "All the DLLs in the solution are
copied to a runtime folder and ran from there. The copy is done on a post
build event in the project." I was not running from the runtime folder. If
I ran the app from the runtime folder by double clicking the exe, it worked.
If I ran from Visual Studio, it did not work. I changed the Debugging -
"Debug Mode" Property from Project to Program and entered in the exe path for
"Start Application". That fixed the problem. With the property set to
Project, the exe was running from the local bin\debug folder and the DLLs
were loaded from the runtime folder.

Could some please explain why this behavior? Is this a security issue?


I suspect that *some* DLLs were being loaded from the runtime folder,
and *some* were being loaded from the local folder. I suspect that the
same DLL (in name) was being loaded from *both* places, one in one
context and one in another - and that's where the problems would have
arisen.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9

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

Similar topics

3
by: Tooc | last post by:
I am trying to pass the type of an object to a method, and then check object references against it to see if they are of that type, using the C# operator is. However, my syntax is wrong - see...
6
by: exits funnel | last post by:
Hello, I've written the following code: //BEGIN CODE #include <iostream> #include <new> #include <cstdlib> using namespace std; class NoMemory {
7
by: John J | last post by:
To write a unary operator- operation that returns the negative of a value is it just as simple as subtracting the value from itself? ie. { return (value - value); } Thanks
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
4
by: August1 | last post by:
I've written an interface and implementation file along with a client source file that allows the use of an overloaded subtraction operator. However, when using the program, I'm running into a...
11
by: Jonny Iversen | last post by:
My VC++ documentation state that this is the one complements operator ~0 = 0xFFFF aka all bits set (swapping all 0's to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000...
3
by: Tooc | last post by:
I am trying to pass the type of an object to a method, and then check object references against it to see if they are of that type, using the C# operator is. However, my syntax is wrong - see...
1
by: Peter Bromley | last post by:
Hi, I have a managed __value type which I am attempting to create and use but there are a number of problems - seemingly in the C++ compiler. From MSDN: operator ~() should be equivalent to...
2
by: Mark P | last post by:
Consider a class in which I redefine operator new(std::size_t): struct A { void* operator new(std::size_t size) {/* my implementation */} }; This has the consequence of hiding the placement...
2
by: Brad Farrell | last post by:
I'm trying to code a line in my .asp that will check for one of three values in a field and either: a) if null, no display b) if set to -.01, show the "Please call..." c) show the price ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.