Sunday, 20 October 2019

Helix Publishing Pipeline - file locks issue on deploy

On my last project when I was implementing Helix Publishing Pipeline I found really bizarre issue. Almost every time I was deploying code by publishing it from Visual Studio, some dlls were locked by w3wp process.

No surprise IIS uses those assemblies but I didn't have such locking problem earlier.

I was digging for hours in the Internet and I found out that IIS uses assembly shadowing. So basically it doesn't use directly dlls from webroot bin, but from its the temp folder.

It can be disabled by this setting

<hostingEnvironment shadowCopyBinAssemblies="false" />

When I set this for test, file locks were all over the place.

Earlier I used Process Explorer and I saw that w3wp locks not only shadowed dlls but as well those from webroot bin, so something was not right there!



More digging eventually gave me information that our issue was self-inflicted: https://stackoverflow.com/a/28019475

In GlassMapperScCustom assemblies were loaded by invoking method
Assembly.LoadFile(assemblyPath) 

which loads exact assemblies and it doesn't take into account shadows.

Instead of that we should always use

Assembly.LoadFrom(assemblyPath) 

which loads shadows as it should be.

That fixed issue with file locks for good!

Share it:

Radosław Kozłowski - Senior Sitecore Developer Radoslaw Kozlowski

Author & Editor

Sitecore MVP, passionate Sitecore & .NET developer and architect. Sitecore Community evangelist.

1 comments: