I am trying to create an assembly dynamically in .Net. However, I cannot figure out how to get the CodeBase property to return a value. Here is an example:
var assemblyName = new AssemblyName { Name = "Whatever", CodeBase = Directory.GetCurrentDirectory() }; var assemblyBuilder = AppDomain.CurrentDomain .DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave); var moduleBuilder = assemblyBuilder.DefineDynamicModule("WhateverModule", "Whatever.dll"); var typeBuilder = moduleBuilder.DefineType("WhateverType", TypeAttributes.Public); var type = typeBuilder.CreateType(); assemblyBuilder.Save("Whatever.dll"); var codeBase = type.Assembly.CodeBase;
Can anyone see what I'm doing wrong?
Explanation: I am trying to extend NUnit with addin, which generates runtime testing methods. He does this by accepting an array of Action delegates. Unfortunately, Reflection is pretty much baked in the structure, so I had to publish classes using the method for each Action delegate. This works fine when I use only the NUnitTestMethod classes, but when I use the NUnitTestFixture, it fails because it is trying to read the CodeBase from the assembly. I did not want to create a physical assembly, but this project was one compromise after another.
source share