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. General Programming
  3. WCF and WF
  4. Getting version of assembly embedded as a resource (SOLVED)

Getting version of assembly embedded as a resource (SOLVED)

Scheduled Pinned Locked Moved WCF and WF
hardwarehelptutorialannouncementlearning
5 Posts 2 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.
  • F Offline
    F Offline
    fjparisIII
    wrote on last edited by
    #1

    I have an assembly embedded as a resource in my application. I'd like to get the System.Version of that assembly. That should be easy but I can't figure out the series of calls needed to accomplish this. I'll try to walk through my problem. I know how to get the version of the executing assembly:

    Assembly assembly = Assembly.GetAssembly(GetType());
    AssemblyName assemblyName = assembly.GetName();
    Version version = assemblyName.Version;

    So if I could figure out how to get the Assembly object of my assembly embedded in my resources, it would be a trivial exercise. I also know how to get a Stream for the embedded resource:

    Uri uri = new Uri("Resources/" + resourceFileName, UriKind.Relative);
    StreamResourceInfo sri = Application.GetResourceStream(uri);
    Stream componentStream = sri.Stream;

    So perhaps there's a way of getting an Assembly from a Stream. Let's see...There is An Assembly.ReflectionOnlyLoad(Byte[]) method that returns an Assembly so all I need is a Byte[] from the Stream:

    Byte[] bytes = new Byte[componentStream.Length];
    int size = componentStream.Read(bytes, 0, (int)componentStream.Length);

    Then I should be able to get the assembly like this:

    Assembly assembly = Assembly.ReflectionOnlyLoad(bytes);

    Putting it all together, I should be able to do this:

    Uri uri = new Uri("Resources/" + resourceFileName, UriKind.Relative);
    StreamResourceInfo sri = Application.GetResourceStream(uri);
    Stream componentStream = sri.Stream;
    Byte[] bytes = new Byte[componentStream.Length];
    int size = componentStream.Read(bytes, 0, (int)componentStream.Length);
    Assembly assembly = Assembly.ReflectionOnlyLoad(bytes);
    AssemblyName assemblyName = assembly.GetName();
    Version version = assemblyName.Version;

    Let me try that...Hmm. It worked. Thanks for listening to me.

    D 1 Reply Last reply
    0
    • F fjparisIII

      I have an assembly embedded as a resource in my application. I'd like to get the System.Version of that assembly. That should be easy but I can't figure out the series of calls needed to accomplish this. I'll try to walk through my problem. I know how to get the version of the executing assembly:

      Assembly assembly = Assembly.GetAssembly(GetType());
      AssemblyName assemblyName = assembly.GetName();
      Version version = assemblyName.Version;

      So if I could figure out how to get the Assembly object of my assembly embedded in my resources, it would be a trivial exercise. I also know how to get a Stream for the embedded resource:

      Uri uri = new Uri("Resources/" + resourceFileName, UriKind.Relative);
      StreamResourceInfo sri = Application.GetResourceStream(uri);
      Stream componentStream = sri.Stream;

      So perhaps there's a way of getting an Assembly from a Stream. Let's see...There is An Assembly.ReflectionOnlyLoad(Byte[]) method that returns an Assembly so all I need is a Byte[] from the Stream:

      Byte[] bytes = new Byte[componentStream.Length];
      int size = componentStream.Read(bytes, 0, (int)componentStream.Length);

      Then I should be able to get the assembly like this:

      Assembly assembly = Assembly.ReflectionOnlyLoad(bytes);

      Putting it all together, I should be able to do this:

      Uri uri = new Uri("Resources/" + resourceFileName, UriKind.Relative);
      StreamResourceInfo sri = Application.GetResourceStream(uri);
      Stream componentStream = sri.Stream;
      Byte[] bytes = new Byte[componentStream.Length];
      int size = componentStream.Read(bytes, 0, (int)componentStream.Length);
      Assembly assembly = Assembly.ReflectionOnlyLoad(bytes);
      AssemblyName assemblyName = assembly.GetName();
      Version version = assemblyName.Version;

      Let me try that...Hmm. It worked. Thanks for listening to me.

      D Offline
      D Offline
      Daniel Vaughan
      wrote on last edited by
      #2

      Hey there, why not publish this as a Tip[^]. :) Daniel Vaughan Follow me on Twitter Blog: DanielVaughan.Orpius.com Open Source Projects: Calcium SDK, Clog Organization: Outcoder of PebbleAge

      F 1 Reply Last reply
      0
      • D Daniel Vaughan

        Hey there, why not publish this as a Tip[^]. :) Daniel Vaughan Follow me on Twitter Blog: DanielVaughan.Orpius.com Open Source Projects: Calcium SDK, Clog Organization: Outcoder of PebbleAge

        F Offline
        F Offline
        fjparisIII
        wrote on last edited by
        #3

        Well, I did it, but previewing and correcting doesn't seem to be nearly as clean as working on the message boards. I made a couple of typos that I saw needed correcting but there doesn't seem to be a Preview button that leaves the edit window open. I ended up having to retype the whole blasted thing, then missed some strings I wanted to bold! Not a pleasant experience.

        D 1 Reply Last reply
        0
        • F fjparisIII

          Well, I did it, but previewing and correcting doesn't seem to be nearly as clean as working on the message boards. I made a couple of typos that I saw needed correcting but there doesn't seem to be a Preview button that leaves the edit window open. I ended up having to retype the whole blasted thing, then missed some strings I wanted to bold! Not a pleasant experience.

          D Offline
          D Offline
          Daniel Vaughan
          wrote on last edited by
          #4

          I just gave it a 5. Daniel Vaughan Follow me on Twitter Blog: DanielVaughan.Orpius.com Open Source Projects: Calcium SDK, Clog Organization: Outcoder of PebbleAge

          F 1 Reply Last reply
          0
          • D Daniel Vaughan

            I just gave it a 5. Daniel Vaughan Follow me on Twitter Blog: DanielVaughan.Orpius.com Open Source Projects: Calcium SDK, Clog Organization: Outcoder of PebbleAge

            F Offline
            F Offline
            fjparisIII
            wrote on last edited by
            #5

            Cool, and thanks! I found editing after the post to be much more friendly, and I was able to bold the expressions I'd missed through my second edit. Fortunately I had rights to edit it because I'd made so many posts up here previously (all questions!).

            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