By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

weird?? inaccessible due to its protection level error

P: n/a
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_some Class.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

Feb 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
milund <mv****@gmail.comwrote:

<snip>
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 - <sk***@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
Feb 7 '07 #2

P: n/a
On 7 Feb., 20:25, Jon Skeet [C# MVP] <s...@pobox.comwrote:
milund <mvl...@gmail.comwrote:

<snip>
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 - <s...@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
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.

Feb 8 '07 #3

P: n/a
On Feb 8, 10:09 am, "milund" <mvl...@gmail.comwrote:
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.
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

Feb 8 '07 #4

P: n/a
On 8 Feb., 12:18, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Feb 8, 10:09 am, "milund" <mvl...@gmail.comwrote:
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.

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

Feb 8 '07 #5

P: n/a
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.

"milund" wrote:
On 8 Feb., 12:18, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Feb 8, 10:09 am, "milund" <mvl...@gmail.comwrote:
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.
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

Feb 10 '07 #6

P: n/a
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
"SerenityPCCS" <Se**********@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
>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.

"milund" wrote:
>On 8 Feb., 12:18, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Feb 8, 10:09 am, "milund" <mvl...@gmail.comwrote:

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.

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


Feb 11 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.