简体   繁体   中英

Create dll file in runtime doesn't work in c#

I am trying to create a DLL file in runtime ,as a matter of fact i need to save an encoded data to DLL .My code is like this :

 class DllFile
    {
        public static void CreateDllFile(string source)
        {
            var provider = new CSharpCodeProvider();
            var options = new CompilerParameters
            {
                OutputAssembly = "test.dll"
            };

        var results = provider.CompileAssemblyFromSource(options, new[] { source });
        }
    }

I expect from this code to create a dll file but it doesn't create

The error is :The pointer for this method was null

Best regards.Any ideas will be appreciated.

Compilation errors are reported via the returned value:

var results = provider.CompileAssemblyFromSource(options, new[] { source });

Now check results , and in particular results.Errors .

You can also check results.NativeCompilerReturnValue - that should be 0 for success, and non-zero for failure.

Any errors would be in the Errors property of the CompilerResults returned from the CompileAssemblyFromSource method. Have you tried printing them out to see if there are errors ?

CompilerResults results = provider.CompileAssemblyFromSource(options, new[] { source });

foreach(CompilerError error in results.Errors)
{
      Console.WriteLine(error.ToString());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM