RuleSetDialog和引用的程序集

时间:2012-01-12 15:22:34

标签: workflow-foundation rule-engine

我正在尝试在生产网站上打开 RuleSetDialog 表单,但它会崩溃并显示消息:

FileNotFoundException: Could not load file or assembly 'IBM.Data.Informix, Version=9.0.0.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208' or one of its dependencies. The system cannot find the file specified.

问题是,这个程序集在我们的项目中被引用,但它在生产站点上不存在,因为将使用不同的数据库。

这是堆栈跟踪:

at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at System.Workflow.Activities.Rules.SimpleRunTimeTypeProvider.get_ReferencedAssemblies()
at System.Workflow.Activities.Rules.SimpleRunTimeTypeProvider.GetTypes()
at System.Workflow.Activities.Rules.Parser..ctor(RuleValidation validation)
at System.Workflow.Activities.Rules.Design.RuleSetDialog..ctor(Type activityType, ITypeProvider typeProvider, RuleSet ruleSet)

我不知道该怎么做。由于我们的机器安装了所有驱动程序,因此在开发和测试期间一切都运行良好,但对于仅安装所需驱动程序的用户而言,情况并非如此。

2 个答案:

答案 0 :(得分:1)

我不认为这是最正确的解决方案,但我可以通过将其添加到我的应用程序来使其工作:

var currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += (o, args) =>
{
     // I resolve the not found assemblies here.
}

希望这可以帮助某人。

答案 1 :(得分:1)

我本周遇到了类似的错误,因为我们需要的dll没有部署在应用程序的主文件夹中,而是部署在一个单独的子文件夹中。我没有找到任何工作方式来告诉RuleEngine在哪里搜索它们。攻击AppDomain对我来说似乎不是最好的解决方案。

在我的例子中,我用来运行RuleEngine的对象没有Extension方法,因此不直接使用引用的程序集作为其方法定义。规则验证不需要引用的程序集。

所以我的解决方法是告诉规则引擎没有引用的程序集。我通过编写自己的ITypeProvider并将其传递给RuleEngine / RuleSetDialog构造函数的构造函数来完成。

我从github(https://github.com/rashiph/DecompliedDotNetLibraries/blob/master/System.Workflow.Activities/System/Workflow/Activities/Rules/SimpleRunTimeTypeProvider.cs)的默认SimpleRunTimeTypeProvider中获取代码,并调整属性ReferencedAssemblies(注释4 LOC),如下所示:

    public ICollection<Assembly> ReferencedAssemblies
    {
        get
        {
            if (this.references == null)
            {
                List<Assembly> list = new List<Assembly>();
                // ADAPTATION TO ORIGINAL SOURCE: tell the RuleEngine that there are no referenced assemblies and hence no Extension Methods
                //foreach (AssemblyName name in this.root.GetReferencedAssemblies())
                //{
                //    list.Add(Assembly.Load(name));
                //}
                this.references = list;
            }
            return this.references;
        }
    }