473,785 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Oddity with 'protected internal' and derivation

I am refactoring some code to move some base classes into a separate
assembly. One of these base classes has a member property which is
'protected internal'. However when I move these base classes to another
assembly, the compiler complains that the override in the derived class,
also declared as 'protected internal', is trying to change the access
modified from 'protected', which is clearly not the case. (I have checked
the metadata in the assembly and the base class property is 'famorassem'.)
If I change the derived class declaration to just 'protected', it works OK.
Anybody have an explanation as to why it is working this way?
Apr 26 '07
13 2827
Hello,
>>Which would mean a circular reference of assemblies.
Which is just OK with .NET, why not?
I don't believe so - as far as I'm aware, if assembly A references
assembly B, the reverse can't be true.
Easily. I've just written a couple such assemblies:

w:\Circular>a1. exe
Created
I'm A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null. I have
a field A2.C2.
I'm A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null. I have
a field A1.C1.
Done

You don't have to take my word for it, you can just check the references
list of System.dll and System.Xml.dll :) Surprisingly, they're circularly-referenced
as well.
For one thing, you've got a problem as to which you compile first...
To reference an assembly at compile-time, all you need is the assembly name,
version, culture, and public key token. All of them are known even before
the assembly is compiled.
You can have circular *class* references, but they need to be in the
same assembly.
No, they needn't. Those C1 and C2 classes of mine each have a field of the
other's type. That compiles, passes peverify.exe, loads, and runs.

It's true that you cannot do circular references in C#, which is mostly because
C# wants to validate everything at compile time, and you cannot verify much
until all the referenced assemblies exist. So it's a bit offtopic in a .csharp
newsgroup, but still possible in the real world ;)

(H) Serge
Apr 26 '07 #11
(I started replying before reading the whole thing - I've left my
comments in rather than taking them all out, in order to explain my
reactions.)

Serge Baltic <ba*****@hypers w.netwrote:
>Which would mean a circular reference of assemblies.
Which is just OK with .NET, why not?
I don't believe so - as far as I'm aware, if assembly A references
assembly B, the reverse can't be true.

Easily. I've just written a couple such assemblies:

w:\Circular>a1. exe
Created
I'm A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null. I have
a field A2.C2.
I'm A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null. I have
a field A1.C1.
Done
How did you compile those then?
You don't have to take my word for it, you can just check the references
list of System.dll and System.Xml.dll :) Surprisingly, they're circularly-referenced
as well.
Indeed, you're right. I'm frankly confused.
For one thing, you've got a problem as to which you compile first...

To reference an assembly at compile-time, all you need is the assembly name,
version, culture, and public key token. All of them are known even before
the assembly is compiled.
But if you add a reference to an assembly, it will check whether or not
that exists, won't it? Otherwise how can it ensure that the type you're
referencing exists?
You can have circular *class* references, but they need to be in the
same assembly.

No, they needn't. Those C1 and C2 classes of mine each have a field of the
other's type. That compiles, passes peverify.exe, loads, and runs.

It's true that you cannot do circular references in C#, which is
mostly because C# wants to validate everything at compile time, and
you cannot verify much until all the referenced assemblies exist. So
it's a bit offtopic in a .csharp newsgroup, but still possible in the
real world ;)
Ah, I see. It all makes sense now - you're not using the C# compiler.
That certainly changes things. Your comment of "Which is just OK with
..NET, why not?" (referring to circular assembly references) implies
that there's no problem with circular references. Not being able to
compile such a situation in C# is certainly a problem for most of us :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 27 '07 #12
Hello,
Ah, I see. It all makes sense now - you're not using the C# compiler.
That certainly changes things. Your comment of "Which is just OK with
.NET, why not?" (referring to circular assembly references) implies
that there's no problem with circular references. Not being able to
compile such a situation in C# is certainly a problem for most of us
:)
Uh … well … I'm sorry, but of course you can write them in C# :) I've rewritten
my example in .cs, and here're two valid circularly-referencing C#-compiled
assemblies:

w:\Circular\01> a1.exe
I'm "A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null". I
can see "A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null".
I'm "A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null". I
can see "A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null".

Using just two .cs files and a few csc.exe calls to compile them. Easy fun.
:)

(H) Serge
Apr 27 '07 #13
Serge Baltic <ba*****@hypers w.netwrote:
Ah, I see. It all makes sense now - you're not using the C# compiler.
That certainly changes things. Your comment of "Which is just OK with
.NET, why not?" (referring to circular assembly references) implies
that there's no problem with circular references. Not being able to
compile such a situation in C# is certainly a problem for most of us
:)

Uh ? well ? I'm sorry, but of course you can write them in C# :) I've rewritten
my example in .cs, and here're two valid circularly-referencing C#-compiled
assemblies:

w:\Circular\01> a1.exe
I'm "A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null". I
can see "A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null".
I'm "A2.C2, A2, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null". I
can see "A1.C1, A1, Version=0.0.0.0 , Culture=neutral , PublicKeyToken= null".

Using just two .cs files and a few csc.exe calls to compile them. Easy fun.
:)
So how did you compile them? I can see how you could compile one
version of assembly A which *didn't* refer to B, then compile B
referring to A, then recompile A referring to B. Hardly the kind of
thing you'd want to do on a regular basis though, is it? In particular,
I suspect you wouldn't be able to do it within Visual Studio, although
admittedly I haven't tried.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 27 '07 #14

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

Similar topics

7
1956
by: Andy Ward | last post by:
Given the following code: class A { protected: int pro; }; class B : public A { public:
28
3429
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
12
1529
by: xxx | last post by:
I'm having a little trouble understanding why a derivative class cannot access a protected member of the base class in the following code: #include <stdio.h> class CBase { protected: int x;
8
2547
by: Carlos J. Quintero | last post by:
Hi, As you know the current keywords "protected internal" (C#) or "Protected Friend" (VB.Net) means "Protected Or internal" (C#) or "Protected Or Friend" (VB.Net), that is, the member is accesible from whichever types inside the assembly or from derived classes included those outside the assembly. The IL has a provision for the "family AND assembly" accesibility level, that is, a member is accesible from derived classes belonging to...
6
12001
by: Sgt. Sausage | last post by:
I know it's not possible, but I need a protected internal interface: protected internal interface ISomeInterface{ // yadda yadda yadda } Basically, I need an interface that is completely accessable from within the assembly (internal), but is not valid outside
2
6062
by: Kolozs, Áron | last post by:
Hi everybody, The C# compiler reports a Compiler Error CS0052 in the following situation: I declared a type marked as "internal": namespace MyNamespace { internal class MyInteralClass
4
6306
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
16
3632
by: Fir5tSight | last post by:
Hi All, I have a small C#.NET program that is as follows: using System; class A { protected int x = 123; }
2
1980
by: jehugaleahsa | last post by:
Hello: I have a public abstract class. The concrete subclasses must pass an instance of an internal class to the abstract class' ctor. I like to make the constructors of my abstract classes protected. However, since it has a parameter that is of an internal type, I am forced to make it internal also. This is fine since no one outside my library can see it.
0
9483
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
10346
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
10157
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
10096
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
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2887
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.