It's my football and I'm going home

We've all created API libraries, and libraries by their nature encourage resuse.
However what happens if you want to be selective in who else uses your assembly?
One simplistic approach would be to ensure that the calling assembly has the same public key


private void CheckCallerAllowed()
{
var myPubKeyToken = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
var entryPubKeyToken = Assembly.GetEntryAssembly().GetName().GetPublicKeyToken();

if (myPubKeyToken.Length != entryPubKeyToken.Length)
    throw new ApplicationException("Assembly not licensed");

for (int idx = 0; idx < myPubKeyToken.Count(); ++idx)
   
if (myPubKeyToken[idx] != entryPubKeyToken[idx])
       
throw new ApplicationException("Assembly not licensed");
}

 

Place a call to the function above in your public interface.

Recent Tweets

Note: For Customization and Configuration, CheckOut Recent Tweets Documentation

Calendar

<<  May 2017  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Month List