Matthijs
Getting the value from "managed" code is no problem as you have shown. I
need to be able to do this from unmanaged code.
I was hoping for a solutoin using the IMetaDataAssemblyImport unmanaged COM
interface. This call looks like:
STDMETHOD(GetAssemblyProps)( // S_OK or error.
mdAssembly mda, // [IN] The Assembly for which
to get the properties.
const VOID **ppbPublicKey, // [OUT] Pointer to the public
key.
ULONG *pcbPublicKey, // [OUT] Count of bytes in the
public key.
ULONG *pulHashAlgId, // [OUT] Hash Algorithm.
LPWSTR szName, // [OUT] Buffer to fill with
name.
ULONG cchName, // [IN] Size of buffer in wide
chars.
ULONG *pchName, // [OUT] Actual # of wide chars
in name.
ASSEMBLYMETADATA *pMetaData, // [OUT] Assembly MetaData.
DWORD *pdwAssemblyFlags) PURE; // [OUT] Flags.
Clearly it returns a pointer to a PublicKey.
But does anybody know how to get the PublicKeyToken from a PublicKey??
Rod
[quoted text, click to view] "Matthijs van der Vleuten" <microsoft-nntp@chroma.mine.nu> wrote in message
news:Og6IkStiFHA.320@TK2MSFTNGP09.phx.gbl...
> Rod da Silva wrote:
> > Hi,
> >
> > I have some unmanaged code and am looking for a way to determine the
fully
> > qualified name of a given assembly DLL. In particular the
PublicKeyToken
> > part of the fully qualified name is proving difficult to determine. I
have
> > found a work around using the SN.EXE tool to list the PublicKeyToken
given
> > an assembly name. My code currently "runs" SN with the -Tp switch and
then
> > captures the output and parses it for the PublicKeyToken. Not very
elegant
> > but it works.
> >
> > Problem is, however, this solution requires the .Net SDK to be installed
and
> > I am looking for a generic way to do this using only the .Net runtime.
> >
> > Anybody have any ideas?
>
> If loading that assembly is no problem, you can try:
>
> Assembly a = System.Reflection.Assembly.LoadFile(pathToAssembly);
> byte[] publicKeyToken = a.GetName().GetPublicKeyToken();
>
> > Thanks,
> > Rod