Несоответствие пакета манифеста сборки - установка не разрешается - PullRequest
0 голосов
/ 13 октября 2019

Ошибка манифеста не устранена, я стараюсь изо всех сил (даже ссылку исходного кода Roslyn на мой проект). Ниже приведен фрагмент кода, который генерирует ошибку. Проект - WINFORM, и в Element Host загрузите сборку Roslyn.

Действия для воспроизведения ошибки

  1. удалите все пакеты изрешение Get-Package |Uninstall-Package -RemoveDependencies -Force

  2. установить каркас на 4.7.2 и Build Platform: x86

  3. удалить все системы. * Referencess
  4. добавить ссылки System, System.Drawing, System.Windows, System.Windows.Forms, System.Data
  5. установить пакет roslynPad.Editor (последний: т.е. 1.0.4) 5.1. установить пакет roslynPad.Windows (последняя версия: 2.4.0) 5.2. установить пакет roslynPad.Roslyn (последний: то есть 2.4.0)
  6. ссылка PresentationCore, PresentationFramework, WindowsBase, WindowsFormsIntegration, UIAutomationProvider
  7. Перейти к ссылкам Dll выбрать все (в Visual Studio) и сделать копию локальным= true.
  8. Перестроить и найти 23 (конфликты между разными версиями) предупреждений.
  9. Проверить подробный журнал сборки (подробность настроена на подробное)

9 **Рекомендуется Stackoverflow: перекомпилировать сборки на некоторых постах. удалите все пакеты и добавьте источник roslynPad.

10 выполните следующее, добавьте источники и сбросьте зависимости

**************************************************************************

 =======  ** RoslynPad.Roslyn ** =======
Microsoft.CodeAnalysis.CSharp ( 3.1.0 ) 
Microsoft.CSharp ( 4.5.0 ) 
System.Threading.Thread ( 4.3.0 )
NETStandardLibrary ( 2.0.3 )

 =======  ** RoslynPad.Roslyn.Windows ** =======
 NETFramework 4.7.2

 =======  ** RoslynPad.Editor.Windows ** =======
 NETCoreApp 3.0 NETFramework 4.7.2


 =======  ** emptyRoslynPad ** =======  
Set Refrence to above projects sources.  
     Install following Package  
         Install-Package AvalonEdit -Version 5.0.4
         Install-Package Microsoft.CodeAnalysis -Version 3.1.0

 **************************************************************************

 11 ReBuild     Still the Error ( Mismatch Assembly ) Exists...
System.IO.FileLoadException
  HResult=0x80131040
  Message=Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Source=emptyRoslynPad
  StackTrace:
   at emptyRoslynPad.Form1.InitializeEditor(String sourceCode) in C:\Users\user_\source\repos\emptyRoslynPad\emptyRoslynPad\Form1.cs:line 118
   at emptyRoslynPad.Form1..ctor() in C:\Users\user_\source\repos\emptyRoslynPad\emptyRoslynPad\Form1.cs:line 27
   at emptyRoslynPad.Program.Main(String[] args) in C:\Users\user_\source\repos\emptyRoslynPad\emptyRoslynPad\Program.cs:line 20

Inner Exception 1:
FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

КОД:

 // Form1.cs //
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Highlighting;
using RoslynPad.Editor;
using RoslynPad.Roslyn;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace emptyRoslynPad
{
    public partial class Form1 : Form
    {
        public Form1() // line 118 is the termination }.
        {
            InitializeComponent(); // line 27

            try
            {
                InitializeEditor("");
                MessageBox.Show("Load without error");
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                //Display or log the error based on your application.
                MessageBox.Show(errorMessage);
            }
            finally
            {

            }
        }


        private RoslynCodeEditor _editor;
        private void InitializeEditor(string sourceCode)
        {
            if (string.IsNullOrWhiteSpace(sourceCode))
                sourceCode = string.Empty;
            _editor = new RoslynCodeEditor();
            // bin\x86\Release
            var workingDirectory = Directory.GetCurrentDirectory();
            var roslynHost = new RoslynHost(additionalAssemblies: new[]
            {
        Assembly.Load("RoslynPad.Roslyn.Windows"),
        Assembly.Load("RoslynPad.Editor.Windows")
    });

            _editor.Initialize(roslynHost, new ClassificationHighlightColors(), workingDirectory, sourceCode);
            _editor.FontFamily = new System.Windows.Media.FontFamily("Consolas");
            _editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            _editor.FontSize = 12.75f;
            elementHost1.Child = _editor;
            this.Controls.Add(elementHost1);

            // Fold the members/parameters by default so the user doesn't have to see them
            var foldingManager = FoldingManager.Install(_editor.TextArea);
            var foldings = new NewFolding[1] {
    new NewFolding(0, sourceCode.Length) { // end before the newline
        Name = "Members/Parameters",
        DefaultClosed = true
    }
};
            foldingManager.UpdateFoldings(foldings, sourceCode.Length);
        }
    }
}

// Program.cs //

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace emptyRoslynPad
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1()); // line 20
        }
    }
}

1 Ответ

0 голосов
/ 14 октября 2019

Решено путем изменения следующего значения в app.config

 <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

независимо от того, имеется ли связь bindingRedirect в app.config, удалите все. перекомпилируйте и добавьте недостающие пакеты. Тада решение работает.

...