Lately I have been hacking some things out with NHibernate. I ran across an interesting issue with calling Assembly.GetManifestResourceStream(). For NHibernate, I have different session factory configuration files for each entity assembly. So I needed to load an embedded resource from an assembly and pass it to NHibernate.
This was my first attempt…
Assembly assembly = this.GetType().Assembly;
assembly.GetManifestResourceStream("nhibernate.cfg.xml");
…which didn’t work.
After some research, I found this article. Basically, you can’t just specify the resource name. You have to specify the entire assembly name before the resource name. Thanks .NET for another wonderfully documented feature that makes no sense.
Assembly assembly = this.GetType().Assembly;
assembly.GetManifestResourceStream(
assembly.GetName().Name + ".nhibernate.cfg.xml");