{"action":"created","issue":{"url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/3","repository_url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent","labels_url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/3/comments","events_url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/3/events","html_url":"https://github.com/jugglingnutcase/Nancy.EmbeddedContent/issues/3","id":139365049,"number":3,"title":"Incorrect assembly searched for static contents when building in \"Release\" mode","user":{"login":"chrnola","id":711598,"avatar_url":"https://avatars.githubusercontent.com/u/711598?v=3","gravatar_id":"","url":"https://api.github.com/users/chrnola","html_url":"https://github.com/chrnola","followers_url":"https://api.github.com/users/chrnola/followers","following_url":"https://api.github.com/users/chrnola/following{/other_user}","gists_url":"https://api.github.com/users/chrnola/gists{/gist_id}","starred_url":"https://api.github.com/users/chrnola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrnola/subscriptions","organizations_url":"https://api.github.com/users/chrnola/orgs","repos_url":"https://api.github.com/users/chrnola/repos","events_url":"https://api.github.com/users/chrnola/events{/privacy}","received_events_url":"https://api.github.com/users/chrnola/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-08T19:07:05Z","updated_at":"2016-03-09T14:17:03Z","closed_at":null,"body":"I noticed that my embedded static content wasn't being served (all of them 404'd) whenever I built my solution in the \"Release\" build configuration and launched my site from outside of the debugger. I enabled Nancy's request tracing functionality and eventually discovered that it was trying to find my static resources in `Nancy.dll` instead of my assembly.\r\n\r\nUltimately this was due to the fact that I was using `Nancy.EmbeddedContent.Conventions.StaticContentsConventionsExtensions.AddEmbeddedDirectory(this IList<Func<NancyContext, string, Response>>, string, string, params string[])` which attempts to infer the correct assembly by calling `Assembly.GetCallingAssembly()`. Unfortunately this method can behave in unexpected ways due to JIT compilation as stated by [Microsoft from their documentation](https://msdn.microsoft.com/library/system.reflection.assembly.getcallingassembly(v=vs.100).aspx):\r\n\r\n> If the method that calls the GetCallingAssembly method is expanded inline by the just-in-time (JIT) compiler, or if its caller is expanded inline, the assembly that is returned by GetCallingAssembly may differ unexpectedly.\r\n\r\nThe workaround for me was to use the overloaded `AddEmbeddedDirectory` that takes an `Assembly` and explicitly pass in a reference to the assembly that housed my static content.\r\n\r\nI believe that the other `AddEmbeddedDirectory` which relies on `Assembly.GetCallingAssembly()` should be deprecated."},"comment":{"url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/comments/194312476","html_url":"https://github.com/jugglingnutcase/Nancy.EmbeddedContent/issues/3#issuecomment-194312476","issue_url":"https://api.github.com/repos/jugglingnutcase/Nancy.EmbeddedContent/issues/3","id":194312476,"user":{"login":"jugglingnutcase","id":238079,"avatar_url":"https://avatars.githubusercontent.com/u/238079?v=3","gravatar_id":"","url":"https://api.github.com/users/jugglingnutcase","html_url":"https://github.com/jugglingnutcase","followers_url":"https://api.github.com/users/jugglingnutcase/followers","following_url":"https://api.github.com/users/jugglingnutcase/following{/other_user}","gists_url":"https://api.github.com/users/jugglingnutcase/gists{/gist_id}","starred_url":"https://api.github.com/users/jugglingnutcase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jugglingnutcase/subscriptions","organizations_url":"https://api.github.com/users/jugglingnutcase/orgs","repos_url":"https://api.github.com/users/jugglingnutcase/repos","events_url":"https://api.github.com/users/jugglingnutcase/events{/privacy}","received_events_url":"https://api.github.com/users/jugglingnutcase/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T14:17:03Z","updated_at":"2016-03-09T14:17:03Z","body":"Taking a look now, i see i've run into something similar to this before and i also use the overloaded method as you can see from the following (i use vb, so avert your :eyes: if you find it offensive :wink:):\r\n\r\n```vb.net\r\n        ' Run through embedded resources to resolve views\r\n        '\r\n        ' Retrieves views embedded in the current assembly\r\n        ' We use the `ContentHelper` class to load the assembly in release mode instead of our custom root path provider\r\n        ' because Nancy gets confused seeing our custom provider and its own and will throw an exception. Also, in addition\r\n        ' i've hidden our custom root path provider under a debug flag because it shouldn't even be present in release mode.\r\n        ' The embedded content provider now handles web resources in release mode.\r\n        Dim assembly As Assembly = GetType(ContentHelper).Assembly\r\n        If Not EmbeddedViewLocationProvider.RootNamespaces.ContainsKey(assembly) Then\r\n            EmbeddedViewLocationProvider.RootNamespaces.Add(assembly, \"Stuff.Content.Views\")\r\n        End If\r\n\r\n        ' Add a path to each resource directory to the static conventions under the key name to simplify resource requests\r\n        ' For ex: Nancy will look through the `Content/js` directory when the browser requests from the js url\r\n        nancyConventions.StaticContentsConventions.AddEmbeddedDirectory(\"js\", assembly, \"Scripts\")\r\n        nancyConventions.StaticContentsConventions.AddEmbeddedDirectory(\"css\", assembly, \"css\")\r\n        nancyConventions.StaticContentsConventions.AddEmbeddedDirectory(\"images\", assembly, \"images\")\r\n```\r\n\r\nSo, i don't mind taking your advice here, but instead of deprecating i think i'll just remove the offending lines of code. i never bothered to publish this on NuGet, so a deprecation won't do much. Somebody can just clone and add that method back in if they want it."}}