PowerShell Does Not Reload Upgraded Assemblies

September 6 2010 12 comments

If you use PowerShell while developing with SharePoint 2010, you may have come across this. After you upgrade your packages, PowerShell uses old versions of the assemblies that were supposed to be upgraded. This is because the assemblies are loaded to PowerShell’s app domain, and as long as they are used from the same app domain, they do not get reloaded. I guess the problem does not exist if you manipulate SharePoint with stsadm, but SharePoint PowerShell Commandlets seem to command SharePoint within the same PowerShell app domain.

The problem has a very simple solution: just close and reopen the PowerShell window. But after you have done that a couple of hundred times, you will probably get… erm… annoyed. I want that every time I invoke my script, it starts in a fresh app domain. That’s why my script starts as follows:

param(
<other script parameters>
[switch]$thisAppDomain
)

if(-not $thisAppDomain)
{
    Write-Host "Invoking script in a new app domain"  -foregroundcolor yellow
    powershell.exe -Command $MyInvocation.Line -thisAppDomain
    return;
}

The code starts a new PowerShell process (and a new app domain) with the same arguments as the current invocation, it just adds one extra argument, -thisAppDomain. I know it’s not bullet proof and fails if your script invocation includes piping, for example. Still, it works most of the time and I am not required to reopen the PowerShell window any more to get the dll’s reloaded. If anyone knows a better way to accomplish the “refreshing” of app domain, please share!

Popularity: 3% [?]

12 comments to “PowerShell Does Not Reload Upgraded Assemblies”

  1. Yury says:

    Thanks.
    But aren`t there any way for unloading assemblies?
    Sometimes i write somthing in powershell ISE and use Add-Type cmdlet for add some c# code.
    ISE is too havy for often restarts.

    Sorry for my english.

  2. magnificent issues altogether, you simply received a new reader.
    What might you recommend about your put up that you
    made some days ago? Any sure?

  3. GAMETIPS says:

    Wow, beautiful site. Thnx ..

  4. thanks for clarifying it :)

  5. sex in nrw says:

    If you are looking for casual contacts with hot girls in EU check them at sex in nrw

  6. Luke says:

    Great upgrade. Would really improve the performance.
    https://www.garagedoorsantabarbara.com/

  7. Hobbyhuren says:

    Hobbyhuren ist eine sehr zugängliche Dating-Seite, auf der Dating nicht immer ernst sein muss. Auch wenn diese Dating-Website in erster Linie für die Suche nach einer Beziehung gedacht ist, ist sie auch der richtige Ort für andere Arten von Spaß und aufregenden Kontakten.

  8. Anunciosex says:

    Anunciosex se ocupó de ti. Es básicamente el primer puerto de escala para cualquiera que entre en el mundo de las citas. Si quieres ir sobre seguro en las citas online, tienes que arrastrarte por donde todo el mundo se arrastra.

  9. Sexe says:

    Sexe permet une inscription gratuite. De plus, vous pouvez parcourir les profils d’intérêts potentiels sans dépenser un centime.

  10. Escort side says:

    Escort side er en matchmaking-tjeneste for voksne sexarbejdere. Dette websted er beregnet til at fungere som et mellemled mellem dig og de prostituerede i dit område. Tænk på det som Uber for dine seksuelle behov.

  11. Hobbynutten ficken ist ideal für kostenlose Kontakte. Du kannst jede Fantasie ausleben, die du hast und einen Service anbieten, den keine andere Person kann. Diese Mädchen brauchen es jetzt und sie sind bereit, dich einzuladen. Du kannst dich kostenlos anmelden und sofort mit ihnen ins Gespräch kommen. Lass sie nur nicht darauf warten. Sie sehnen sich schon so lange danach, wie sie sich erinnern können, und sie brauchen es jetzt. Gib ihnen, was sie brauchen, und du wirst immer mit ihren Körpern belohnt werden.

Leave a Reply