【问题标题】:RuleSetDialog and referenced assembliesRuleSetDialog 和引用的程序集
【发布时间】:2012-01-12 15:22:34
【问题描述】:

我正在尝试在生产站点上打开 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)

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

【问题讨论】:

  • 您找到解决方法了吗?

标签: workflow-foundation rule-engine


【解决方案1】:

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

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

所以我的解决方法是告诉规则引擎没有引用的程序集。我通过编写自己的 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;
        }
    }

【讨论】:

  • 太棒了。我自己从来没有真正解决过这个问题。将更多 dll 打包到安装包中更容易。谢谢,这实际上解决了一些其他问题。
【解决方案2】:

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

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

希望这可以帮助某人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多