Answer the question
In order to leave comments, you need to log in
The necessary references are not included in the assembly. How to fix?
Good afternoon!
There is a class:
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
using System.Reflection;
namespace namespace1
{
public class AClass
{
public void Run(string Code)
{
// Формируем зависимости
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
ScriptOptions options = ScriptOptions.Default.AddReferences(assemblies);
// Запускаем скрипт
var result = CSharpScript.RunAsync(Code, options);
}
}
}
string code = @"using Excel = NetOffice.ExcelApi; "
+ @"Excel.Application ExcelApp = new Excel.Application(); ";
NetOffice.ExcelApi.Application SomeVar = new NetOffice.ExcelApi.Application();
Answer the question
In order to leave comments, you need to log in
You can dynamically load the required assembly.
To do this, you need to subscribe to the
AppDomain.CurrentDomain.AssemblyResolve event
and your code will have to do the following:
If the assembly is loaded, return the already loaded one,
If the assembly has not yet been loaded, then return Assembly.LoadFrom("path to the assembly file");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question