Click here to Skip to main content
15,745,973 members
Home / Discussions / ASP.NET


QuestionError - can not create enum dynamically Pin
$unil Dhiman27-Sep-09 8:40
$unil Dhiman27-Sep-09 8:40 
Hi All,
I am trying to create Enum Dynamically.
When I try to Save dll It gives me error - "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" I am also writing code snippet :-

AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName aName = new AssemblyName("TempAssembly");
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
eb.DefineLiteral("Low", 0);
eb.DefineLiteral("High", 1);
Type finished = eb.CreateType();
ab.Save(aName.Name + ".dll");

I got error at last line.
Please help me.
your help is appreciated.

Sunil Dhiman
AnswerRe: Error - can not create enum dynamically Pin
Abhijit Jana27-Sep-09 9:02
professionalAbhijit Jana27-Sep-09 9:02 
AnswerRe: Error - can not create enum dynamically Pin
Abhishek Sur27-Sep-09 9:20
professionalAbhishek Sur27-Sep-09 9:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.