I am busy with a WPF application. To keep things simple I am embedding all assemblies into the application, and then I load them using the OnResolve
event.
Everything worked great, until the point where I had to reference NHibernate.dll
.
The Nhibernate assembly is embedded, and I can load it, however, it has dependencies, and I am not sure how to load it's dependencies at the time of loading NHibernate.dll
.
Here is my OnResolve event handler:
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = new AssemblyName(args.Name);
string path = assemblyName.Name + ".dll";
if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
{
path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
}
using (Stream stream = executingAssembly.GetManifestResourceStream(path))
{
if (stream == null)
return null;
byte[] assemblyRawBytes = new byte[stream.Length];
stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
return Assembly.Load(assemblyRawBytes);
}
}
Any help would be appreciated :)
Aucun commentaire:
Enregistrer un commentaire