SOLVED

Apply-PnPProvisioningTemplate : Cannot access a closed Stream. At line:1 char:1 + Apply-PnPProvision

%3CLINGO-SUB%20id%3D%22lingo-sub-44118%22%20slang%3D%22en-US%22%3EApply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvision%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44118%22%20slang%3D%22en-US%22%3E%3CP%3ETodays%20issue%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20am%20using%20the%20latest%20Powershell%20extension%20and%20each%20tilme%20i%20run%20Appl-PnPProvioningTemplate%20i%20get%20the%20error%26nbsp%3BApply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvision.%20I%20enabled%20logging%20and%20i%20dont%20see%20anything%20that%20could%20hint%20the%20cause%20of%20the%20error.%20Same%20thing%20happen%20if%20I%20use%20c%23%20code%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-45125%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-45125%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20anyone%20who%20stumble%20up%20on%20this%20error%20please%20follow%20up%20on%20the%20issue%20report%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F1050%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F1050%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-45075%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-45075%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20followed%20the%20steps%20you%20took%20and%20I%20got%20the%20same%20error%20as%20you%20got.%20The%20file%20causing%20the%20error%20was%20simple.master.%20During%20Provisioning%20PnP%20is%20trying%20to%20overwrite%20the%20file%20while%20it%20is%20checked%20out%20during%20conversion%20of%20the%20simple.html%20file%20to%20a%20master%20page.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20able%20to%20fix%20the%20error%20and%20get%20the%20desired%20results%20following%20the%20steps%20below%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3ERename%20your%20.pnp%20file%20to%20a%20.zip%20file%3C%2FLI%3E%3CLI%3EExtract%20the%20contents%20of%20the%20file%3C%2FLI%3E%3CLI%3EIn%20the%20extracted%20files%20folder%20locate%20your%20template%20file%20in%20the%20Files%20folder%20(it's%20named%20%5Bsomeguid%5D.xml)%3C%2FLI%3E%3CLI%3EOpen%20the%20file%20in%20your%20favorite%20XML%20editor%3C%2FLI%3E%3CLI%3ELocate%20the%20pnp%3Afile%20element%20for%20your%20.master%20file%20and%20remove%20the%20element%3C%2FLI%3E%3CLI%3ESave%20your%20XML%20file%3C%2FLI%3E%3CLI%3EZIP%20the%20contents%20of%20your%20folder%20again%20and%20give%20it%20the%20same%20name%20as%20the%20original%20.pnp%20file%20you%20extracted%3C%2FLI%3E%3CLI%3EApply%20the%20.pnp%20file%20to%20your%20site%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20consider%20this%20a%20bug%20in%20PnP%20and%20I'd%20suggest%20you%20to%20submit%20an%20issue%20in%20PnP%20describing%20your%20steps%20to%20reproduce%20and%20my%20steps%20to%20work%20around%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-45061%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-45061%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EIn%20order%20to%20replicate%20the%20issue%20try%20the%20following%3C%2FSTRONG%3E%3CBR%20%2F%3E1.%20Create%20two%20site%20collection%20using%20the%20publishing%20template%20one%20will%20be%20used%20to%20apply%20your%20custom%20branding%20and%20the%20other%20is%20the%20one%20you%20will%20use%20powershell%20to%20apply%20said%20branding%3CBR%20%2F%3E2.%20Create%20a%20simple%20html%20file%20and%20call%20it%20whatever%20you%20want.%20in%20my%20case%20I%20called%20it%20simple.html%3CBR%20%2F%3Emy%20file%20only%20had%20this%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CTITLE%3EPage%20Title%3C%2FTITLE%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CH1%20id%3D%22toc-hId-1990892457%22%3EThis%20is%20a%20Heading%3C%2FH1%3E%3CBR%20%2F%3E%3CP%3EThis%20is%20a%20paragraph.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E3.%20Use%20design%20manger%20to%20upload%20this%20template%20to%20the%20Master%20Page%20Gallery%20of%20the%20site%20collection%20you%20want%20to%20apply%20branding%20to.%3CBR%20%2F%3E4.%20Go%20to%20Edit%20Master%20Pages%20in%20Design%20Manager%20and%20then%20click%20Convert%20an%20HTML%20file%20to%20a%20SharePoint%20master%20page.%3CBR%20%2F%3E5.%20Select%20the%20html%20file%20you%20uploaded%20earlier%20and%20this%20will%20convert%20your%20file%20to%20master%20page%20file.%3CBR%20%2F%3E6.%20In%20design%20manager%20gor%20to%20Publish%20and%20Apply%20design%20the%20click%20on%20go%20o%20the%20master%20page%20gallery.%3CBR%20%2F%3E7.%20Go%20to%20were%20you%20had%20uploded%20you%20html%20file%20and%20you%20will%20see%20the%20.master%20file.%20Ensure%20all%20files%20are%20published%20and%20checked%20in.%3CBR%20%2F%3E8.%20Go%20to%20site%20Settings%20and%20click%20on%20Master%20page.%20In%20the%20drop%20downbox%20select%20your%20newly%20created%20master%20page.%20This%20will%20apply%20you%20custom%20branding.%3CBR%20%2F%3EBasically%20i%20followed%20the%20steps%20here%20using%20the%20simpliest%20of%20html%20file%20with%20no%20site%20assets%20%22%3CA%20href%3D%22http%3A%2F%2Fwww.sharepointempower.com%2FBlog%2FPost%2F3%2FSharePoint-2013-branding-step-by-step%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.sharepointempower.com%2FBlog%2FPost%2F3%2FSharePoint-2013-branding-step-by-step%3C%2FA%3E%22%3C%2FP%3E%3CP%3EThe%20next%20steps%20are%20to%20now%20get%20the%20provisioning%20template%20using%20powershell%20from%20your%20branded%20site%20the%20use%20powershell%20to%20apply%20the%20branding%20to%20you%20other%20site%20collection%20(make%20sure%20it%20was%20created%20using%20publishing%20template)%3C%2FP%3E%3CP%3EI%20used%20the%20following%20parameters%20when%20I%20was%20getting%20the%20publishing%20template%20-PesistBrandingFiles%20-PersistPublishing%20Files.%20I%20find%20that%20if%20i%20dont%20use%20PersistPublishingFiles%20it%20doesnt%20provision%20my%20html%20file.%3C%2FP%3E%3CP%3EAs%20far%20you%20can%20see%20what%20i%20am%20doing%20is%20basic%20and%20its%20not%20working%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44890%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44890%22%20slang%3D%22en-US%22%3EPersistBrandingFiles%20should%20extract%20the%20MasterPage%20you%20applied%2C%20the%20sitelogo%20you%20configured%2C%20the%20alternate%20CSS%20you%20specified%20and%20all%20the%20files%20related%20to%20the%20applied%20Composed%20Look%20(if%20any).%20There%20are%202%20more%20PersistFiles%20parameters.%20Any%20other%20file%20not%20targeted%20by%20these%20parameters%20should%20be%20added%20to%20the%20template%20manually.%3CBR%20%2F%3E%3CBR%20%2F%3ESee%20this%20page%20for%20all%20documentation%20on%20the%20cmdlet%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FGetPnPProvisioningTemplate.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FGetPnPProvisioningTemplate.md%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44877%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44877%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20this%20something%20%26nbsp%3BI%20have%20to%20do%20manually%20or%20this%20%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pl-c1%22%3EGet-PnPProvisioningTemplate%20-PersistBrandingFiles%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3Edo%20all%20of%20that%20for%20me.%20If%20its%20manul%20can%20you%20point%20me%20in%20the%20right%20direction.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20guys%20for%20all%20your%20help%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44876%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44876%22%20slang%3D%22en-US%22%3EYes%2C%20the%20Provisioning%20Engine%20is%20able%20to%20provision%20all%20these%20types%20of%20files%20as%20long%20as%20they%20are%20defined%20correctly%20in%20your%20template%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44872%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44872%22%20slang%3D%22en-US%22%3EAs%20it%20stands%20this%20is%20the%20only%20error%20I%20am%20getting.%20I%20am%20working%20against%20a%20SharePoint%20Online%20environment.%20Another%20quick%20question.%20Does%20the%20provisioning%20engine%20provision%20all%20the%20assets%20for%20the%20master%20page%20css%2C%20js%20files%20etc%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44871%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44871%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20I%20understand%20you%20got%20a%20different%20error%20after%20you%20checked%20in%20the%20file.%20Before%20the%20file%20was%20checked%20in%20you%20got%20%22Cannot%20access%20a%20closed%20stream%22.%20After%20checking%20in%20you%20got%20%22%3CSPAN%3ETHe%20contents%20of%20the%20attachment%20doesnt%20match%20its%20file%20type%3C%2FSPAN%3E%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20familiar%20with%20that%20last%20error%20message.%20When%20exactly%20do%20you%20get%20this%20message%3F%20Are%20you%20working%20against%20a%20SharePoint%20Online%20environment%20or%20on-premises%3F%20I%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44863%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44863%22%20slang%3D%22en-US%22%3E%3CP%3Estill%20having%20this%20issue.%20I%20am%20not%20sure%20if%20i%20mentioned%20that%20this%20is%20a%20publishinfg%20site.%20If%20the%20error%20is%20because%20of%20a%20checked%20out%20file%20how%20can%20i%20know%20what%20file%20is%20being%20checked%20out.%20I%20created%20over%20the%20site%20and%20every%20site%20assets%20i%20added%20i%20ensured%20that%20it%20was%20published%20and%20check%20in%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44566%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44566%22%20slang%3D%22en-US%22%3E%3CP%3Emist%20that%20one%20and%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1803%22%20target%3D%22_blank%22%3E%40Paul%20Pascha%3C%2FA%3E%26nbsp%3Bdid%20not%20inform%20me%20%3B)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44547%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44547%22%20slang%3D%22en-US%22%3E%3CP%3ESince%20june%202016%20release%20of%20PnP%20you%20can%20extract%20templates%20to%20a%20file%20with%20a%20.pnp%20extension%20which%20is%20effectively%20a%20ZIP%20file%20containing%20all%20provisioning%20artifacts%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fchannel9.msdn.com%2Fblogs%2FOfficeDevPnP%2FPnP-Provisioning-Engine-Introducing-PnP-file-type-for-template-handling%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fchannel9.msdn.com%2Fblogs%2FOfficeDevPnP%2FPnP-Provisioning-Engine-Introducing-PnP-file-type-for-template-handling%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44527%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44527%22%20slang%3D%22en-US%22%3E%3CP%3Ejust%20a%20guess%20but%20where%20is%20the%20proviosing%20template%3F%20it%20is%20in%20a%20zip%3F%20as%20far%20as%20i%20know%20you%20can%20not%20use%20a%20zip%20to%20apply%20template.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Emaybe%20%26nbsp%3Bi%20am%20wrong%20here%20but%20if%20you%20do%20a%20get%20template%20you%20get%20xml%20which%20you%20can%20provision%20back..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44517%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44517%22%20slang%3D%22en-US%22%3E%3CP%3EAlso%20please%20see%20the%20template%20I%20am%20trying%20to%20apply%20downloadable%20from%20the%20link%20below%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F0BwBQnwZDg9M6M09KS0F1REE0MU0%2Fview%3Fusp%3Dsharing%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F0BwBQnwZDg9M6M09KS0F1REE0MU0%2Fview%3Fusp%3Dsharing%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44191%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44191%22%20slang%3D%22en-US%22%3E%3CP%3EFollowed%20instruction%20her%20and%20i%20found%20one%20file%20that%20was%20checked%20out.%20However%20i%20still%20get%20the%20error%20after%20checking%20it%20in.%20Each%20time%20i%20try%20to%20upload%20the%20.pnp%20file%20i%20am%20geting%20the%20error%20%22THe%20contents%20of%20the%20attachment%20doesnt%20match%20its%20file%20type%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44168%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44168%22%20slang%3D%22en-US%22%3E%3CP%3ESee%20also%20this%20issue%20I%20reported%20a%20few%20months%20ago%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F796%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F796%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44139%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44139%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20error%20message%20typically%20indicates%20a%20Checked-out%20file.%20There's%20probably%20a%20pnp%3AFile%20definition%20in%20your%20template%20for%20a%20File%20that's%20checked%20out.%20Could%20this%20be%20your%20issue%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44134%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44134%22%20slang%3D%22en-US%22%3E%3CP%3Eplease%20post%20the%20xml%20so%20we%20can%20look%20at%20what%20is%20happening.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-44130%22%20slang%3D%22en-US%22%3ERe%3A%20Apply-PnPProvisioningTemplate%20%3A%20Cannot%20access%20a%20closed%20Stream.%20At%20line%3A1%20char%3A1%20%2B%20Apply-PnPProvi%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-44130%22%20slang%3D%22en-US%22%3EIt%20will%20be%20helpful%20to%20check%20this%20issue%2C%20if%20you%20can%20post%20the%20xml%20used.%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Todays issue

 

Hi am using the latest Powershell extension and each tilme i run Appl-PnPProvioningTemplate i get the error Apply-PnPProvisioningTemplate : Cannot access a closed Stream. At line:1 char:1 + Apply-PnPProvision. I enabled logging and i dont see anything that could hint the cause of the error. Same thing happen if I use c# code

18 Replies
Highlighted
It will be helpful to check this issue, if you can post the xml used.
Highlighted

please post the xml so we can look at what is happening.

Highlighted

This error message typically indicates a Checked-out file. There's probably a pnp:File definition in your template for a File that's checked out. Could this be your issue?

Highlighted
Highlighted

Followed instruction her and i found one file that was checked out. However i still get the error after checking it in. Each time i try to upload the .pnp file i am geting the error "THe contents of the attachment doesnt match its file type"

 

Highlighted
Highlighted

just a guess but where is the proviosing template? it is in a zip? as far as i know you can not use a zip to apply template.

 

maybe  i am wrong here but if you do a get template you get xml which you can provision back..

 

Highlighted

Since june 2016 release of PnP you can extract templates to a file with a .pnp extension which is effectively a ZIP file containing all provisioning artifacts

 

https://channel9.msdn.com/blogs/OfficeDevPnP/PnP-Provisioning-Engine-Introducing-PnP-file-type-for-t...

Highlighted
Highlighted

still having this issue. I am not sure if i mentioned that this is a publishinfg site. If the error is because of a checked out file how can i know what file is being checked out. I created over the site and every site assets i added i ensured that it was published and check in

Highlighted

If I understand you got a different error after you checked in the file. Before the file was checked in you got "Cannot access a closed stream". After checking in you got "THe contents of the attachment doesnt match its file type".

 

I'm not familiar with that last error message. When exactly do you get this message? Are you working against a SharePoint Online environment or on-premises? I

Highlighted
As it stands this is the only error I am getting. I am working against a SharePoint Online environment. Another quick question. Does the provisioning engine provision all the assets for the master page css, js files etc
Highlighted
Yes, the Provisioning Engine is able to provision all these types of files as long as they are defined correctly in your template
Highlighted

Is this something  I have to do manually or this  

Get-PnPProvisioningTemplate -PersistBrandingFiles

do all of that for me. If its manul can you point me in the right direction.

 

Thanks again guys for all your help 

Highlighted
PersistBrandingFiles should extract the MasterPage you applied, the sitelogo you configured, the alternate CSS you specified and all the files related to the applied Composed Look (if any). There are 2 more PersistFiles parameters. Any other file not targeted by these parameters should be added to the template manually.

See this page for all documentation on the cmdlet:
https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/GetPnPProvisioningTemplate.md
Highlighted

In order to replicate the issue try the following
1. Create two site collection using the publishing template one will be used to apply your custom branding and the other is the one you will use powershell to apply said branding
2. Create a simple html file and call it whatever you want. in my case I called it simple.html
my file only had this
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
3. Use design manger to upload this template to the Master Page Gallery of the site collection you want to apply branding to.
4. Go to Edit Master Pages in Design Manager and then click Convert an HTML file to a SharePoint master page.
5. Select the html file you uploaded earlier and this will convert your file to master page file.
6. In design manager gor to Publish and Apply design the click on go o the master page gallery.
7. Go to were you had uploded you html file and you will see the .master file. Ensure all files are published and checked in.
8. Go to site Settings and click on Master page. In the drop downbox select your newly created master page. This will apply you custom branding.
Basically i followed the steps here using the simpliest of html file with no site assets "http://www.sharepointempower.com/Blog/Post/3/SharePoint-2013-branding-step-by-step"

The next steps are to now get the provisioning template using powershell from your branded site the use powershell to apply the branding to you other site collection (make sure it was created using publishing template)

I used the following parameters when I was getting the publishing template -PesistBrandingFiles -PersistPublishing Files. I find that if i dont use PersistPublishingFiles it doesnt provision my html file.

As far you can see what i am doing is basic and its not working

Highlighted
Solution

I've followed the steps you took and I got the same error as you got. The file causing the error was simple.master. During Provisioning PnP is trying to overwrite the file while it is checked out during conversion of the simple.html file to a master page.

 

I was able to fix the error and get the desired results following the steps below:

 

  1. Rename your .pnp file to a .zip file
  2. Extract the contents of the file
  3. In the extracted files folder locate your template file in the Files folder (it's named [someguid].xml)
  4. Open the file in your favorite XML editor
  5. Locate the pnp:file element for your .master file and remove the element
  6. Save your XML file
  7. ZIP the contents of your folder again and give it the same name as the original .pnp file you extracted
  8. Apply the .pnp file to your site

 

I consider this a bug in PnP and I'd suggest you to submit an issue in PnP describing your steps to reproduce and my steps to work around this.

 

Hope this helps!

Highlighted

For anyone who stumble up on this error please follow up on the issue report here:

https://github.com/SharePoint/PnP-Sites-Core/issues/1050