简体   繁体   中英

What should I use instead of LoadWithPartialName()?

I'm loading an assembly with LoadWithPartialName(), but VS tells me that it's obsolete and to use Load() instead. However, I can't find any convenient overload.

There is a Load(string) with asks for a "full-name" which, if I understood correctly the MSDN docs, includes things like the version number.

There is also a Load (string, Evidence) which accepts a "Display name". The problem is I don't have the slightest idea what the "Display Name" is, as the "Partial Name" I was using with the first function doesn't seem to work.

So, how should it be done?

The following article explains why it's obsolete: http://blogs.msdn.com/suzcook/archive/2003/05/30/57159.aspx .

Bottom line is: use Load and give it the version number.

Here's what I did. I am loading "Microsoft.AnalysisServices" into PowerShell as my example.

  1. Open the GAC folder that has the assembly. It can be any one of the following:
    • C:\Windows\Microsoft.NET\assembly\GAC_32
    • C:\Windows\Microsoft.NET\assembly\GAC_64
    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL
  2. In that folder, open the folder for your assembly.
  3. In that folder, you will see another folder that looks like this:
    • v4.0_15.0.0.0__89845dcd8080cc91
  4. Break this down into the component parts:
    • v4.0 (I think this is the .NET version, but we don't need it here.)
    • 15.0.0.0 (This is the version you're looking for)
    • 89845dcd8080cc91 (This is the public key)
  5. Now you can create your assembly string.

     [System.Reflection.Assembly]::Load("Microsoft.AnalysisServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91")

For .NET assemblies, Culture is always neutral .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM