Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error - can not create enum dynamically

Error - can not create enum dynamically

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    unil Dhiman
    wrote on last edited by
    #1

    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

    N M A 3 Replies Last reply
    0
    • U unil Dhiman

      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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK, ab.Save() will save the files to AppDomain.CurrentDomain.BaseDirectory. What value are you getting in AppDomain.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

      A U 2 Replies Last reply
      0
      • U unil Dhiman

        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

        M Offline
        M Offline
        Michael Eber
        wrote on last edited by
        #3

        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.

        U 1 Reply Last reply
        0
        • N N a v a n e e t h

          I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK, ab.Save() will save the files to AppDomain.CurrentDomain.BaseDirectory. What value are you getting in AppDomain.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

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • U unil Dhiman

            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

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Michael Eber

              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.

              U Offline
              U Offline
              unil Dhiman
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • N N a v a n e e t h

                I am not getting the point of creating a dynamic enum in ASP.NET. AFAIK, ab.Save() will save the files to AppDomain.CurrentDomain.BaseDirectory. What value are you getting in AppDomain.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

                U Offline
                U Offline
                unil Dhiman
                wrote on last edited by
                #7

                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

                N 1 Reply Last reply
                0
                • U unil Dhiman

                  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

                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #8

                  $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

                  U 1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    $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

                    U Offline
                    U Offline
                    unil Dhiman
                    wrote on last edited by
                    #9

                    Hi Navaneeth Sorry !!! I got busy in an urgent task at that time.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups