Error - can not create enum dynamically
-
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. I am working on Vista Premium. I gave permissions to Network Service User but still not solved. Please help me. your help is appreciated. Regards, Sdhimann
-
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. I am working on Vista Premium. I gave permissions to Network Service User but still not solved. Please help me. your help is appreciated. Regards, Sdhimann
I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK,
ab.Save()
will save the files toAppDomain.CurrentDomain.BaseDirectory
. What value are you getting inAppDomain.CurrentDomain.BaseDirectory
? If the path you get is outside the website area, ASP.NET can't write to there.Navaneeth How to use google | Ask smart questions
-
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. I am working on Vista Premium. I gave permissions to Network Service User but still not solved. Please help me. your help is appreciated. Regards, Sdhimann
If this code is all you are trying to do, then you are wasting your time. Just create the Enum class for you enumerator. On the other hand if this is a test for more complex process you should discuss this instead. For example, building enumerators from the database is a matter of Googling
Emitting Enumerators using T4
. Then learn how to use T4 to dynamically build your classes inline with your code. -
I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK,
ab.Save()
will save the files toAppDomain.CurrentDomain.BaseDirectory
. What value are you getting inAppDomain.CurrentDomain.BaseDirectory
? If the path you get is outside the website area, ASP.NET can't write to there.Navaneeth How to use google | Ask smart questions
Navaneeth, I have already answered him last night about the problem. I dont know why he is putting the same question again and again in the forum rather than replying the last replies. :-D :doh: :doh:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
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. I am working on Vista Premium. I gave permissions to Network Service User but still not solved. Please help me. your help is appreciated. Regards, Sdhimann
You have asked the same question over here http://www.codeproject.com/Forums/12076/ASP-NET.aspx?fid=12076&select=3213626&tid=3213626[^] and few member also answered you. Then what is the reason of posting the question again ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
If this code is all you are trying to do, then you are wasting your time. Just create the Enum class for you enumerator. On the other hand if this is a test for more complex process you should discuss this instead. For example, building enumerators from the database is a matter of Googling
Emitting Enumerators using T4
. Then learn how to use T4 to dynamically build your classes inline with your code.Hi Michael, Thanks for reply. I tried to Inherite "Enum" class. but it is giving an error message - "cannot derive from special class 'System.Enum'" Please help me how to create Enum Dynamically. Regards, Sdhimann
-
I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK,
ab.Save()
will save the files toAppDomain.CurrentDomain.BaseDirectory
. What value are you getting inAppDomain.CurrentDomain.BaseDirectory
? If the path you get is outside the website area, ASP.NET can't write to there.Navaneeth How to use google | Ask smart questions
Hi Navaneeth I want to use Enum in Web parts to show DropDown. Web parts use only Enum to bind Dropdown. is there ant other way to solve this problem ? thanks
-
Hi Navaneeth I want to use Enum in Web parts to show DropDown. Web parts use only Enum to bind Dropdown. is there ant other way to solve this problem ? thanks
$unil Dhiman wrote:
is there ant other way to solve this problem ?
May be. But you haven't answered to my questions which I asked on my last post.
Navaneeth How to use google | Ask smart questions
-
$unil Dhiman wrote:
is there ant other way to solve this problem ?
May be. But you haven't answered to my questions which I asked on my last post.
Navaneeth How to use google | Ask smart questions
Hi Navaneeth Sorry !!! I got busy in an urgent task at that time.