Eugene Paul
Eugene Paul

Reputation: 39

C# Assembly is deactivated and cannot run any code error

Hopefully I explain this well enough.

When I try to access a dll I created (I access this dll via reflection)I get an error at a certain point saying its "deactivated". I can run code from this only up to the point where it is trying to access code from the ReferencedAssemblies specified by their path.

I create a .dll with this code and it creates a .dll in the correct directory.

public class DLLCreator

{
    private string path = @"G:\Scripts\Bremca\Library\";

    [Start]
    public void Start()
    {
        List<string> paths = new List<string>();
        //Class File Location
        DirectoryInfo d = new DirectoryInfo(path);
        FileInfo[] files = d.GetFiles("*.cs");
        foreach(FileInfo file in files)
        {
            if(!file.Name.Contains(this.ToString()))
                paths.Add(file.FullName);
                
        }
        string[] pathsArray = paths.ToArray();
        CSharpCodeProvider provider = new CSharpCodeProvider();
        CompilerParameters parameters = new CompilerParameters();   
        parameters.ReferencedAssemblies.Add("System.dll"); 
        parameters.ReferencedAssemblies.Add("System.Drawing.dll");
        parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        parameters.ReferencedAssemblies.Add("System.Runtime.dll");
        parameters.ReferencedAssemblies.Add(@"G:\Scripts\Bremca\Bin\Eplan.EplApi.AFu.dll");
        parameters.ReferencedAssemblies.Add(@"G:\Scripts\Bremca\Bin\Eplan.EplApi.Baseu.dll");
        parameters.ReferencedAssemblies.Add(@"G:\Scripts\Bremca\Bin\Eplan.EplApi.HEServicesu.dll");
        parameters.ReferencedAssemblies.Add(@"G:\Scripts\Bremca\Bin\Eplan.EplApi.DataModelu.dll");
        parameters.ReferencedAssemblies.Add(@"G:\Scripts\Bremca\Bin\Eplan.EplApi.MasterDatau.dll");
        parameters.ReferencedAssemblies.Add("System.Collections.dll");
        parameters.ReferencedAssemblies.Add("System.Runtime.InteropServices.dll");
        parameters.ReferencedAssemblies.Add("System.Xml.dll");
        parameters.ReferencedAssemblies.Add("System.Xml.ReaderWriter.dll");
        parameters.ReferencedAssemblies.Add("System.Linq.dll");
        parameters.ReferencedAssemblies.Add("System.Core.dll");
        parameters.ReferencedAssemblies.Add("System.ComponentModel.Primitives.dll");
        parameters.ReferencedAssemblies.Add("System.Drawing.Primitives.dll");
        parameters.OutputAssembly = path+"Library.dll";
        parameters.GenerateInMemory = true; //True - memory generation, false - external file generation
        parameters.GenerateExecutable = false; //True - exe file generation, false - dll file generation
        //Compile Assembly
        CompilerResults results = provider.CompileAssemblyFromFile(parameters, pathsArray);
        if (results.Errors.HasErrors)
        {
            StringBuilder sb = new StringBuilder();
            foreach (CompilerError error in results.Errors)
            {
                sb.AppendLine(String.Format("Error ({0}): {1}", error.ErrorNumber, error.ErrorText));
            }
            throw new InvalidOperationException(sb.ToString());
        }
        provider.Dispose();
    }
}

enter image description here

What exactly is this error and how do I resolve it?

Upvotes: 0

Views: 85

Answers (0)

Related Questions