{"action":"created","issue":{"url":"https://api.github.com/repos/OfficeDev/PnP/issues/641","labels_url":"https://api.github.com/repos/OfficeDev/PnP/issues/641/labels{/name}","comments_url":"https://api.github.com/repos/OfficeDev/PnP/issues/641/comments","events_url":"https://api.github.com/repos/OfficeDev/PnP/issues/641/events","html_url":"https://github.com/OfficeDev/PnP/issues/641","id":67489143,"number":641,"title":"Provisioning Engine does not work on Azure Web Jobs","user":{"login":"levalencia","id":6962857,"avatar_url":"https://avatars.githubusercontent.com/u/6962857?v=3","gravatar_id":"","url":"https://api.github.com/users/levalencia","html_url":"https://github.com/levalencia","followers_url":"https://api.github.com/users/levalencia/followers","following_url":"https://api.github.com/users/levalencia/following{/other_user}","gists_url":"https://api.github.com/users/levalencia/gists{/gist_id}","starred_url":"https://api.github.com/users/levalencia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/levalencia/subscriptions","organizations_url":"https://api.github.com/users/levalencia/orgs","repos_url":"https://api.github.com/users/levalencia/repos","events_url":"https://api.github.com/users/levalencia/events{/privacy}","received_events_url":"https://api.github.com/users/levalencia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-04-10T02:04:45Z","updated_at":"2015-04-10T23:15:57Z","closed_at":null,"body":"I have a template, I only need 2 activate 3 features and add one property bag.\r\n\r\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<pnp:SharePointProvisioningTemplate ID=\"xx\" Version=\"1.0\"\r\n  xmlns:pnp=\"http://schemas.dev.office.com/PnP/2015/03/ProvisioningSchema\"\r\n  xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\r\n  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n  <pnp:PropertyBagEntries>\r\n    <pnp:PropertyBagEntry Key=\"xx.PlantillasIntranet.Version\" Value =\"1\" />\r\n  </pnp:PropertyBagEntries>\r\n  <pnp:Features>\r\n    <pnp:SiteFeatures>\r\n      <pnp:Feature ID=\"f6924d36-2fa8-4f0b-b16d-06b7250180fa\" />\r\n      <!-- publishing feature on site-->\r\n    </pnp:SiteFeatures>\r\n    <pnp:WebFeatures>\r\n      <pnp:Feature ID=\"41e1d4bf-b1a2-47f7-ab80-d5d6cbba3092\" />\r\n      <!-- push notifications feature on web-->\r\n      <pnp:Feature ID=\"94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb\" />\r\n      <!-- publishing feature on web-->\r\n    </pnp:WebFeatures>\r\n  </pnp:Features>\r\n</pnp:SharePointProvisioningTemplate>\r\nand my code is like this:\r\n\r\npublic static void ActivateFeatures(ClientContext cc)\r\n{\r\n    XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(AppDomain.CurrentDomain.BaseDirectory+ \"/Template/\",\"\");\r\n    string templateName = \"features.xml\";\r\n\r\n    // Load the template\r\n    ProvisioningTemplate p2 = provider.GetTemplate(templateName);\r\n\r\n    // Apply template to existing site\r\n    try\r\n    {\r\n        cc.Web.ApplyProvisioningTemplate(p2);\r\n    }\r\n    catch (Exception ex)\r\n    {\r\n        System.Diagnostics.Trace.TraceError(ex.Message);\r\n    }\r\n    System.Diagnostics.Trace.TraceInformation(\"App installed finished\");\r\n}\r\n}\r\n\r\nOn debug mode I can see that the template has been loaded on p2, because I can see the variables correctly set for property bags and features\r\n\r\nhowever on the ApplyProvisionTemplate line I get this:\r\n\r\nA first chance exception of type 'Microsoft.SharePoint.Client.CollectionNotInitializedException' occurred in Microsoft.SharePoint.Client.Runtime.dll\r\n\r\nThis worked perfectly fine on an azure web site (Provider hosted app)\r\n\r\nvoid SimpleJob_TimerJobRun(object sender, TimerJobRunEventArgs e)\r\n        {\r\n            Console.WriteLine(\"Timer Job Started\");\r\n            try\r\n            {\r\n\r\n                bool containsKey = e.WebClientContext.Web.PropertyBagContainsKey(\"Vinculosc.PlantillasIntranet.Aprovisionado\");\r\n                if (containsKey) //El sitio es un sitio al que se le ha instalado la app de Intranet\r\n                {\r\n                    e.WebClientContext.Load(e.WebClientContext.Web, p => p.Title);\r\n                    e.WebClientContext.ExecuteQueryRetry();\r\n                    Console.WriteLine(\"Site contains key Vinculosc.PlantillasIntranet.Aprovisionado {0}\", e.Url);\r\n\r\n                    string aprovisionado = e.WebClientContext.Web.GetPropertyBagValueString(\"Vinculosc.PlantillasIntranet.Aprovisionado\", \"0\");\r\n                    if (aprovisionado == \"0\")\r\n                    {\r\n                        Stopwatch stopWatch = new Stopwatch();\r\n                        stopWatch.Start();\r\n                        Helpers.ActivateFeatures(e.WebClientContext);\r\n                        string libraryName = \"ConfiguracionColores\";\r\n\r\nbug also documented here\r\nhttp://sharepoint.stackexchange.com/questions/137862/how-to-use-the-pnp-provisioning-engine-with-an-azure-job"},"comment":{"url":"https://api.github.com/repos/OfficeDev/PnP/issues/comments/91713928","html_url":"https://github.com/OfficeDev/PnP/issues/641#issuecomment-91713928","issue_url":"https://api.github.com/repos/OfficeDev/PnP/issues/641","id":91713928,"user":{"login":"erwinvanhunen","id":7666381,"avatar_url":"https://avatars.githubusercontent.com/u/7666381?v=3","gravatar_id":"","url":"https://api.github.com/users/erwinvanhunen","html_url":"https://github.com/erwinvanhunen","followers_url":"https://api.github.com/users/erwinvanhunen/followers","following_url":"https://api.github.com/users/erwinvanhunen/following{/other_user}","gists_url":"https://api.github.com/users/erwinvanhunen/gists{/gist_id}","starred_url":"https://api.github.com/users/erwinvanhunen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erwinvanhunen/subscriptions","organizations_url":"https://api.github.com/users/erwinvanhunen/orgs","repos_url":"https://api.github.com/users/erwinvanhunen/repos","events_url":"https://api.github.com/users/erwinvanhunen/events{/privacy}","received_events_url":"https://api.github.com/users/erwinvanhunen/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T23:15:57Z","updated_at":"2015-04-10T23:15:57Z","body":"are you deploying to a standard team site? and if so, are you deploying to the same site when testing in both environments (e.g. local dev machine and azure webjob)\r\n\r\nThe current master branch has an issue when you try to deploy to a site that has one or more associated groups missing (e.g. Associated Visitors Group, Associated Members Group or Associated Owners Group)"}}