Home All Groups Group Topic Archive Search About

How to Create WinForms client and ClassLib server as one assembly?

Author
12 Feb 2007 12:02 AM
Joseph Geretz
I'd like to break up my aplication into a WinForm executable, plus a class
library containing application utility functions. But I don't want any
client other than my own application to have access to my application
library. Isn't this the point of an 'assembly'? So how can I generate these
two artifacts as belonging to the same assembly? Is this possible with
Visual Studio 2005?

Thanks!

- Joe Geretz -
Author
12 Feb 2007 2:20 AM
Patrick Steele
In article <eMVvWkjTHHA.***@TK2MSFTNGP05.phx.gbl>, jgeretz@nospam.com
says...
> I'd like to break up my aplication into a WinForm executable, plus a class
> library containing application utility functions. But I don't want any
> client other than my own application to have access to my application
> library. Isn't this the point of an 'assembly'? So how can I generate these
> two artifacts as belonging to the same assembly? Is this possible with
> Visual Studio 2005?

Use different assemblies and CAS (Code Access Security).  There was an
overview posted in the newsgroups about a week ago:

http://tinyurl.com/2nwefz

Are all your drivers up to date? click for free checkup

Author
12 Feb 2007 11:46 PM
Alvin Bruney [MVP]
I'm not sure how and why you see CAS as preventing the access. Were you
thinking programmatically? The way I read the question seemed to imply it
was other than programmatically. Perhaps OP can clarify.

As a suggestion, why not use a windows control library?

--
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


Show quoteHide quote
"Patrick Steele" <patr***@mvps.org> wrote in message
news:MPG.203998da2fc84f689896f4@msnews.microsoft.com...
> In article <eMVvWkjTHHA.***@TK2MSFTNGP05.phx.gbl>, jgeretz@nospam.com
> says...
>> I'd like to break up my aplication into a WinForm executable, plus a
>> class
>> library containing application utility functions. But I don't want any
>> client other than my own application to have access to my application
>> library. Isn't this the point of an 'assembly'? So how can I generate
>> these
>> two artifacts as belonging to the same assembly? Is this possible with
>> Visual Studio 2005?
>
> Use different assemblies and CAS (Code Access Security).  There was an
> overview posted in the newsgroups about a week ago:
>
> http://tinyurl.com/2nwefz
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele
Author
14 Feb 2007 2:47 PM
Patrick Steele
In article <OiOWIAwTHHA.5***@TK2MSFTNGP06.phx.gbl>, "Alvin Bruney
[MVP]" <some guy without an email address> says...
> I'm not sure how and why you see CAS as preventing the access. Were you
> thinking programmatically? The way I read the question seemed to imply it
> was other than programmatically. Perhaps OP can clarify.

To me, it sounded like he wanted to break his "utility functions" into a
separate assembly, but only wanted his WinForms app to be able to access
that assembly.  The link I posted was to a similar question and showed
how to use strong keys and attributes to control who could make calls
into an assembly.

But perhaps the OP could clarify exactly what they want?  ;)

Author
16 Feb 2007 6:33 PM
Joseph Geretz
Hi Patrick,

Yes, you state the case correctly; this is exactly what I'd like to do. I
see how CAS can acheive this, however CAS seems more of an administrative
tool than a development option. For a commercial product which will be
installed all over the place, I don't see how CAS can be a viable solution
unless CAS rules can be manipulated programmatically, or via our installer.
Would this be possible?

Thanks,

- Joseph Geretz -

Show quoteHide quote
"Patrick Steele" <patr***@mvps.org> wrote in message
news:MPG.203ceb22fff768be9896fa@msnews.microsoft.com...
> In article <OiOWIAwTHHA.5***@TK2MSFTNGP06.phx.gbl>, "Alvin Bruney
> [MVP]" <some guy without an email address> says...
>> I'm not sure how and why you see CAS as preventing the access. Were you
>> thinking programmatically? The way I read the question seemed to imply it
>> was other than programmatically. Perhaps OP can clarify.
>
> To me, it sounded like he wanted to break his "utility functions" into a
> separate assembly, but only wanted his WinForms app to be able to access
> that assembly.  The link I posted was to a similar question and showed
> how to use strong keys and attributes to control who could make calls
> into an assembly.
>
> But perhaps the OP could clarify exactly what they want?  ;)
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele
Author
16 Feb 2007 8:46 PM
Patrick Steele
In article <uPXJ5ifUHHA.1***@TK2MSFTNGP06.phx.gbl>, jgeretz@nospam.com
says...
> Hi Patrick,
>
> Yes, you state the case correctly; this is exactly what I'd like to do. I
> see how CAS can acheive this, however CAS seems more of an administrative
> tool than a development option. For a commercial product which will be
> installed all over the place, I don't see how CAS can be a viable solution
> unless CAS rules can be manipulated programmatically, or via our installer.
> Would this be possible?

I believe the link I posted suggested that you simply strong-name your
assemblies that want to call your utility assembly.  Then, your utility
assembly methods (or maybe the whole assembly?) has an attribute to
demand a specific strong-name public key from all callers.  Since only
your assemblies are signed with the proper key, they will be the only
ones allowed to call the utility assembly.

I don't think you'll need to manipulate any CAS rules for that.

Author
18 Feb 2007 8:43 PM
Joseph Geretz
Thanks Patrick,

Yes, that article mentions StrongNameIdentityPermissionAttribute which will
do the trick for me. Further explanation at:
http://www.morganskinner.com/Articles/StrongNameIdentityPermission/

Thanks,

- Joe Geretz -

Show quoteHide quote
"Patrick Steele" <patr***@mvps.org> wrote in message
news:MPG.203fe2364d71835f989709@msnews.microsoft.com...
> In article <uPXJ5ifUHHA.1***@TK2MSFTNGP06.phx.gbl>, jgeretz@nospam.com
> says...
>> Hi Patrick,
>>
>> Yes, you state the case correctly; this is exactly what I'd like to do. I
>> see how CAS can acheive this, however CAS seems more of an administrative
>> tool than a development option. For a commercial product which will be
>> installed all over the place, I don't see how CAS can be a viable
>> solution
>> unless CAS rules can be manipulated programmatically, or via our
>> installer.
>> Would this be possible?
>
> I believe the link I posted suggested that you simply strong-name your
> assemblies that want to call your utility assembly.  Then, your utility
> assembly methods (or maybe the whole assembly?) has an attribute to
> demand a specific strong-name public key from all callers.  Since only
> your assemblies are signed with the proper key, they will be the only
> ones allowed to call the utility assembly.
>
> I don't think you'll need to manipulate any CAS rules for that.
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele

Bookmark and Share