473,503 Members | 9,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exporting certain classes in assembly

is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.

Thanks
Oct 14 '08 #1
8 3213
puzzlecracker wrote:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
public vs internal ?

Arne
Oct 14 '08 #2
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
puzzlecracker wrote:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.

public vs internal ?

Arne
That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, making those internal
would break my implementation.
Oct 14 '08 #3
On Mon, 13 Oct 2008 20:14:30 -0700, <ab****@gmail.comwrote:
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>puzzlecracker wrote:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.

public vs internal ?

Arne

That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, making those internal
would break my implementation.
First of all, are you the original poster? If so, please don't switch
back and forth between identities. It's hard enough to keep track of
people who use pseudonyms, without them using _multiple_ pseudonyms so
that we never know who it is we're talking to or responding to.

Second, surely Arne's talking about classes in your library, not the
client. Assuming your client isn't itself a library, accessibility of
things in the client have nothing to do with what's "exported outside",
and even if it is, it only exports what it itself declares. Just because
it references something, that doesn't cause that referenced thing to be
exposed.

There's nothing about your reply to Arne's post that makes me think that
his own response wasn't relevant or helpful. Your reply seems more like a
non sequitur to me.

As is usually the case, if you would post a concise-but-complete code
sample that illustrates whatever accessibility issue you're dealing with,
it would be a lot more likely that someone could provide some specific
advice that addresses your need.

Pete
Oct 14 '08 #4

"ab****@gmail.com" wrote:
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
puzzlecracker wrote:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
public vs internal ?

Arne

That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, making those internal
would break my implementation.
You can use the StrongNameIdentityPermission to limit calling code to known
assemblies.

http://msdn.microsoft.com/en-us/libr...ermission.aspx

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 14 '08 #5
On Oct 14, 1:59*am, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
"ab2...@gmail.com" wrote:
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
puzzlecracker wrote:
is there a way to create a library *(assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
public vs internal ?
Arne
That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, *making those internal
would break my implementation.

You can use the StrongNameIdentityPermission to limit calling code to known
assemblies.

http://msdn.microsoft.com/en-us/libr....permissions.s...

--
Happy Coding!
Morten Wennevik [C# MVP]
Class cannot be internal, hence I would need to make constructors and
member methods to prevent internal classes from leaking to outside?

thanks
Oct 14 '08 #6
On Oct 14, 8:43 am, puzzlecracker <ironsel2...@gmail.comwrote:
>
Class cannot be internal, hence I would need to make constructors and
member methods to prevent internal classes from leaking to outside?
Why not? Inside an assembly, an internal class is only visible to the
other classes in that assembly. Public classes are visible outside
the assembly.

If the client references the assembly, it can only see the public
classes. The internal classes will not be visible to it.

Could you please clarify your comment about "making constructors and
member methods to prevent internal classes from leaking to outside"?

Or could you provide a simple and complete code sample that
illustrates why you can't use internal classes?

Chris
Oct 14 '08 #7

"puzzlecracker" wrote:
On Oct 14, 1:59 am, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
"ab2...@gmail.com" wrote:
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
puzzlecracker wrote:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
public vs internal ?
Arne
That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, making those internal
would break my implementation.
You can use the StrongNameIdentityPermission to limit calling code to known
assemblies.

http://msdn.microsoft.com/en-us/libr....permissions.s...

--
Happy Coding!
Morten Wennevik [C# MVP]

Class cannot be internal, hence I would need to make constructors and
member methods to prevent internal classes from leaking to outside?

thanks
Using StrongNameIdentityPermission it doesn't matter what visibility the
classes have. You can even put it on the entire assembly if you want nothing
at all available to unknown assemblies. However, you are not guaranteed that
identity permissions won't get bypassed by priviliged code, in which case you
may have no other option than to compare the current assembly's public key to
the calling assembly's public key in every constructor, using code similar to
the below

void CheckAssemblies()
{
Assembly currentAssembly = Assembly.GetAssembly(this.GetType());
Assembly callingAssembly = Assembly.GetEntryAssembly();

byte[] currentKeyData = currentAssembly.GetName().GetPublicKey();
byte[] callingKeyData = callingAssembly.GetName().GetPublicKey();

if (currentKeyData.Length != callingKeyData.Length)
throw new SecurityException("Illegal calling assembly");

for (int i = 0; i < currentKeyData.Length; i++)
{
if (currentKeyData[i] != callingKeyData[i])
throw new SecurityException("Illegal calling assembly");
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 15 '08 #8
ab****@gmail.com wrote:
On Oct 13, 10:25 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>puzzlecracker wrote:
>>is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
public vs internal ?

That could cause a problem. Say my client classes reference util
classes, that I don't want to export outside, making those internal
would break my implementation.
You will need to explain what you want.

I read the above as "if make class X internal to prevent
it from being used outside the assembly, then I can not
use it outside the assembly which is a problem".

You can not both eat your cake and have your cake.

If you need more granularity in access then maybe
InternalsVisibleTo can help you.

Arne
Oct 16 '08 #9

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

Similar topics

0
1732
by: Robert Jacobson | last post by:
Hi, I have a number of classes in one assembly. I'd like to use XSD.exe to generate a schema for just one class ("Parse Rules") and its nested child classes. Is there an attribute that will...
18
2018
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
7
2601
by: Gustavo L. Fabro | last post by:
Greetings! Some classes that once compiled without problems on VS 2003 have now problems on VS 2005 Beta 1. I'm talking about a __nogc class that is exported with __declspec(dllexport). The...
2
2234
by: paul | last post by:
I am exporting a class from a managed dll created in Visual C++ 2005 Express. In A.h header file I have // A.h public ref class A {}; In the same module, I create a new class to be exported...
18
6484
by: Peter Gummer | last post by:
This is a design question. I have a project containing a dozen or so classes with protected internal constructors. My reason for having protected internal constructors is to prevent classes...
2
3159
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
4
1624
by: =?Utf-8?B?QWw=?= | last post by:
Hello, I'm writing a service using VS2005 and C#. I've found that only the objects used as parameters in WebMethods get exported to proxy dlls and the Service Description. I'd like my service...
12
7225
by: 2b|!2b==? | last post by:
I want to export my C++ classes in a DLL, using ordinal # - rather than by name. Will anyone care to enumerate through the steps required to do this? I am already failiar with exporting classes...
15
7361
by: Grey Alien | last post by:
I have a class that contains a std::map variable. I need to export the class via a DLL. the class looks something like this: class MyClass { public: MyClass(); MyClass(const MyClass&); ...
0
7095
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...
1
7015
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...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
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 project—planning, coding, testing,...
1
5026
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...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
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 ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.