我知道这个话题有很多回复,但是我在其中找到的示例代码并不适用于每个.dll文件。
我使用了this的示例。
public App()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly);
}
static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
//We dont' care about System Assemblies and so on...
if (!args.Name.ToLower().StartsWith("wpfcontrol")) return null;
Assembly thisAssembly = Assembly.GetExecutingAssembly();
//Get the Name of the AssemblyFile
var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
//Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (resources.Count() > 0)
{
var resourceName = resources.First();
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
var block = new byte[stream.Length];
stream.Read(block, 0, block.Length);
return Assembly.Load(block);
}
}
return null;
}
当我创建了一个只有一个窗口和一个按钮的小程序时,它可以工作,但是使用我的“大”dll时却不能工作。这个“大”dll的设置与我的小程序相同。
我无法想象为什么它有时可以工作,有时又不能工作。我也试过用ICSharp.AvalonEdit.dll测试,但没有成功。
有人能想象错误在哪里吗?
编辑1:
当我启动我的程序时,它说找不到我的dll。
编辑2:
我想我已经找到了我的问题的核心。如果我要合并的dll之一包含对其他dll的引用,那么我就会遇到FileNotFound异常。有人知道如何加载/添加内部所需的dll吗?
编辑3:
当我使用Jiří Polášek的代码时,它对一些人有效。我的Fluent显示错误“请附加具有样式的ResourceDictionary。但我已经在我的App.xaml中完成了这个”。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>