NRefactory - 丢失文件

问题描述 投票:0回答:1

当我尝试使用 NRefactory 时,我仍然收到 System.IO.FileNotFound 异常。 我尝试了很多方法让它发挥作用: - 使用NuGet包,自动安装Mono.Cecil - 下载了 NRefactory 和 Mono.Cecil,并从 VS2010 编译了所有 DLL。

我做错了什么? 这是错误转储:

    [System.IO.FileNotFoundException]   
    {"Could not load file or assembly 'ICSharpCode.NRefactory, Version=4.2.0.8783,
    Culture=neutral, PublicKeyToken=efe927acf176eea2' or one of its dependencies. 
    The system cannot find the file specified.":"ICSharpCode.NRefactory, 
    Version=4.2.0.8783, Culture=neutral, PublicKeyToken=efe927acf176eea2"}  
    System.IO.FileNotFoundException

编辑: 这是导致问题的代码:

    List<CodeElement> methodsInvokedByGivenMethod = GetInvokedMethods(methodName, fileName);

这是方法体:

    private List<CodeElement> GetInvokedMethods(string methodName, string itemWhereMethodIs)
    {
        MessageBox.Show("I am here");
        try
        {
            using (var fs = File.OpenRead(itemWhereMethodIs))
            {
                using (var parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StreamReader(fs)))
                {
                    parser.Parse();
                }
            }
        }
        catch (System.IO.FileNotFoundException fnf)
        {
            // This exception arises in Nrefactory...WTF? 0_0
            SetToolStripText("There is exception :(");
            return null;
        }
    }

更重要的是,异常没有被该方法内的 try-catch 块捕获,而是发生在该方法之外 -> 调用该方法时,但在该方法内的任何代码行之前。

c# visual-studio-2010 .net nrefactory
1个回答
0
投票

我知道这个帖子已经晚了,但我的答案可以帮助其他人(或后来的我),因为我发现你的帖子正在寻找答案。 在运行当前 NRefactory 源代码(大约 7 年前)的 WinForms 演示项目时,我遇到了“ICSharpCode.NRefactory.Cecil not found”异常问题。

我通过以下方式修复了它:

  • 在项目 ICSharpCode.NRefactory.Demo 中添加对项目 ICSharpCode.NRefactory.Cecil 的引用
  • 将解决方案切换到 x86 而不是默认的“任何 Cpu”(不过我不知道这一步是否是强制性的)

它有效:

© www.soinside.com 2019 - 2024. All rights reserved.