Discussion:
weird?? inaccessible due to its protection level error
(too old to reply)
milund
2007-02-07 08:56:15 UTC
Permalink
I have a "funny" after upgrading to .NET2.0.

The following code is placed inside an unsafe method in assembly "A"

System.Object myIUnknownObject =
Marshal.GetObjectForIUnknown((System.IntPtr)m_someClass.MyProperty);

SomeClass is declared public in assembly "B".
MyProperty get is declared public and written in managed C++ (old
syntax) like this.

__property IUnknown* get_MyProperty()
{
return (IUnknown*)m_pStuff->GetStuff();
}


This works fine when assembly "B" is compiled under VS2003 and .NET1.1
When assembly "B" is compiled under VS2005 and .NET2.0 I get this
error (when compiling assembly "A"): "error CS0122:
'B.SomeClass.MyProperty' is inaccessible due to its protection level"

In both cases assembly "A" is compiled with VS2005 and .NET2.0

What has changed from .NET1.1 to .NET2.0 and how do I correct this?
(Note that I actually can get it to work using reflection, but that is
not the point - I would like to understand what is wrong here).

thanks,
Michael
Jon Skeet [C# MVP]
2007-02-07 19:25:26 UTC
Permalink
milund <***@gmail.com> wrote:

<snip>
Post by milund
What has changed from .NET1.1 to .NET2.0 and how do I correct this?
(Note that I actually can get it to work using reflection, but that is
not the point - I would like to understand what is wrong here).
I suggest you have a look at assembly B (and particularly MyProperty)
using Reflector, compiled first with 2003 and then with 2005. My guess
is that you'll find the accessibility changes...
--
Jon Skeet - <***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
milund
2007-02-08 10:09:09 UTC
Permalink
Post by Jon Skeet [C# MVP]
<snip>
Post by milund
What has changed from .NET1.1 to .NET2.0 and how do I correct this?
(Note that I actually can get it to work using reflection, but that is
not the point - I would like to understand what is wrong here).
I suggest you have a look at assembly B (and particularly MyProperty)
using Reflector, compiled first with 2003 and then with 2005. My guess
is that you'll find the accessibility changes...
--
If replying to the group, please do not mail me too
Looking in reflector I see for both versions of assembly B:
public __gc class SomeClass: public System::IDisposable
{
<snip>
public: __property IUnknown __gc** get_MyProperty();
<snip>
}

Also dissasembling the getter method shows the same code.
Jon Skeet [C# MVP]
2007-02-08 11:18:07 UTC
Permalink
Post by milund
public __gc class SomeClass: public System::IDisposable
{
<snip>
public: __property IUnknown __gc** get_MyProperty();
<snip>
}
Also dissasembling the getter method shows the same code.
So, given that there must be *some* difference between the two
assemblies (if one works and the other doesn't) - run them both
through ildasm and run diff on the generated files...

Jon
milund
2007-02-08 13:04:08 UTC
Permalink
Post by Jon Skeet [C# MVP]
Post by milund
public __gc class SomeClass: public System::IDisposable
{
<snip>
public: __property IUnknown __gc** get_MyProperty();
<snip>
}
Also dissasembling the getter method shows the same code.
So, given that there must be *some* difference between the two
assemblies (if one works and the other doesn't) - run them both
through ildasm and run diff on the generated files...
Jon
Unfortunately that doesn't tell me very much. (It is a big assembly
and stuff has moved around - I have tried to compare all sections
involving MyProperty and I can't see anything strange...
I also tried to run ildasm with the /pubonly flag - and MyProperty
turns up fine.

I wonder if it has anything to do with the unsafe keyword - it is just
about the only place we use it...

Michael
SerenityPCCS
2007-02-10 03:41:00 UTC
Permalink
I had a bit of code that I received this error on after "upgrading" to Net
2.0... the method in question was listed as protected originally. After I
changed it to protected internal, it worked fine.
Post by milund
Post by Jon Skeet [C# MVP]
Post by milund
public __gc class SomeClass: public System::IDisposable
{
<snip>
public: __property IUnknown __gc** get_MyProperty();
<snip>
}
Also dissasembling the getter method shows the same code.
So, given that there must be *some* difference between the two
assemblies (if one works and the other doesn't) - run them both
through ildasm and run diff on the generated files...
Jon
Unfortunately that doesn't tell me very much. (It is a big assembly
and stuff has moved around - I have tried to compare all sections
involving MyProperty and I can't see anything strange...
I also tried to run ildasm with the /pubonly flag - and MyProperty
turns up fine.
I wonder if it has anything to do with the unsafe keyword - it is just
about the only place we use it...
Michael
Alvin Bruney [MVP]
2007-02-11 14:08:23 UTC
Permalink
Actually, there is quite a bit of issues with migration stemming from the
wizard. Even in the case of a smooth compile, there may be run-time issues.
Unit tests can help in that regard.
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
Post by SerenityPCCS
I had a bit of code that I received this error on after "upgrading" to Net
2.0... the method in question was listed as protected originally. After I
changed it to protected internal, it worked fine.
Post by milund
Post by Jon Skeet [C# MVP]
Post by milund
public __gc class SomeClass: public System::IDisposable
{
<snip>
public: __property IUnknown __gc** get_MyProperty();
<snip>
}
Also dissasembling the getter method shows the same code.
So, given that there must be *some* difference between the two
assemblies (if one works and the other doesn't) - run them both
through ildasm and run diff on the generated files...
Jon
Unfortunately that doesn't tell me very much. (It is a big assembly
and stuff has moved around - I have tried to compare all sections
involving MyProperty and I can't see anything strange...
I also tried to run ildasm with the /pubonly flag - and MyProperty
turns up fine.
I wonder if it has anything to do with the unsafe keyword - it is just
about the only place we use it...
Michael
Loading...