Which referenes being used?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett

    #1

    Which referenes being used?

    If I believe certain project references (VS.NET) aren't being used, how can
    this be confirmed?

    Thanks,
    Brett


  • James Curran

    #2
    Re: Which referenes being used?

    Remove them, one at a time, and recompile. If you get an error, put it
    back. If not, move on to the next.

    --
    --
    Truth,
    James Curran
    [erstwhile VC++ MVP]

    Home: www.noveltheory.com Work: www.njtheater.com
    Blog: www.honestillusion.com Day Job: www.partsearch.com

    "Brett" <no@spam.com> wrote in message
    news:udHF6NwVFH A.1508@tk2msftn gp13.phx.gbl...[color=blue]
    > If I believe certain project references (VS.NET) aren't being used, how[/color]
    can[color=blue]
    > this be confirmed?
    >
    > Thanks,
    > Brett
    >
    >[/color]


    Comment

    • Alan Pretre

      #3
      Re: Which referenes being used?

      "Brett" <no@spam.com> wrote in message
      news:udHF6NwVFH A.1508@tk2msftn gp13.phx.gbl...[color=blue]
      > If I believe certain project references (VS.NET) aren't being used, how
      > can this be confirmed?[/color]

      Hi. Delete the reference and recompile. If there are errors, it _was_ being
      used and you need to put it back in. If it compiles OK, then it was
      extraneous.

      -- Alan


      Comment

      • Brett

        #4
        Re: Which referenes being used?

        I was hoping there was a more efficient way.

        Will removing the unused reference shrink the overall assembly size?

        VS.NET will add certain references I don't always need - system.data,
        system.xml. Are there any cases these should remain if I know they will not
        be used?

        Thanks,
        Brett
        "James Curran" <jamescurran@mv ps.org> wrote in message
        news:e3$gIZwVFH A.1508@tk2msftn gp13.phx.gbl...[color=blue]
        > Remove them, one at a time, and recompile. If you get an error, put it
        > back. If not, move on to the next.
        >
        > --
        > --
        > Truth,
        > James Curran
        > [erstwhile VC++ MVP]
        >
        > Home: www.noveltheory.com Work: www.njtheater.com
        > Blog: www.honestillusion.com Day Job: www.partsearch.com
        >
        > "Brett" <no@spam.com> wrote in message
        > news:udHF6NwVFH A.1508@tk2msftn gp13.phx.gbl...[color=green]
        >> If I believe certain project references (VS.NET) aren't being used, how[/color]
        > can[color=green]
        >> this be confirmed?
        >>
        >> Thanks,
        >> Brett
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Alan Pretre

          #5
          Re: Which referenes being used?

          "Brett" <no@spam.com> wrote in message
          news:%23UqlljwV FHA.2960@TK2MSF TNGP15.phx.gbl. ..[color=blue]
          > Will removing the unused reference shrink the overall assembly size?[/color]

          Not much if any size difference, but it will load a little faster since the
          system doesn't need to locate and open the referenced assemblies.
          [color=blue]
          > VS.NET will add certain references I don't always need - system.data,
          > system.xml. Are there any cases these should remain if I know they will
          > not be used?[/color]

          Nah go ahead and get rid of them. They are so commonly used that VS just
          assumes you'll need them. It will be a slight annoyance in the future if it
          turns out you do need one of them.

          -- Alan


          Comment

          • Mattias Sjögren

            #6
            Re: Which referenes being used?

            [color=blue]
            >I was hoping there was a more efficient way.[/color]

            Not sure what you consider efficient. But you can also just open the
            compiled assemlby in a tool like Ildasm and look which references are
            there (".assembly extern" records in IL Asm syntax). The C# compiler
            will remove unused references.

            [color=blue]
            >Will removing the unused reference shrink the overall assembly size?[/color]

            No

            [color=blue]
            >VS.NET will add certain references I don't always need - system.data,
            >system.xml. Are there any cases these should remain if I know they will not
            >be used?[/color]

            No



            Mattias

            --
            Mattias Sjögren [MVP] mattias @ mvps.org
            http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
            Please reply only to the newsgroup.

            Comment

            • Bruce Wood

              #7
              Re: Which referenes being used?

              >> Will removing the unused reference shrink the overall assembly size?

              [color=blue]
              > Not much if any size difference, but it will load a little faster[/color]
              since the[color=blue]
              > system doesn't need to locate and open the referenced assemblies.[/color]

              Do you mean that the C# compiler isn't smart enough not to insert code
              to load assemblies that aren't used by the code? I would have thought
              that either the compiler / CLR would load assemblies on "first use", so
              if you don't call them, they don't get loaded, or at least not build in
              code to load assemblies that aren't used in the code.

              The "first use" method would seem the most efficient: what if your
              program uses some large assembly but the user never takes an action
              that would cause it to be called? Would the CLR load it when your app
              starts up, anyway, even if the user never did anything that would
              require that assembly? Now I'm curious. :)

              Comment

              • Alan Pretre

                #8
                Re: Which referenes being used?

                "Bruce Wood" <brucewood@cana da.com> wrote in message
                news:1115925717 .986868.169760@ g43g2000cwa.goo glegroups.com.. .[color=blue]
                > Do you mean that the C# compiler isn't smart enough not to insert code
                > to load assemblies that aren't used by the code? I would have thought
                > that either the compiler / CLR would load assemblies on "first use", so
                > if you don't call them, they don't get loaded, or at least not build in
                > code to load assemblies that aren't used in the code.[/color]

                According to Matthias' other post, the C# compiler will eliminate unused
                references. I wasn't aware of that one.

                -- Alan


                Comment

                • Willy Denoyette [MVP]

                  #9
                  Re: Which referenes being used?


                  "Bruce Wood" <brucewood@cana da.com> wrote in message
                  news:1115925717 .986868.169760@ g43g2000cwa.goo glegroups.com.. .[color=blue][color=green][color=darkred]
                  >>> Will removing the unused reference shrink the overall assembly size?[/color][/color]
                  >
                  >[color=green]
                  >> Not much if any size difference, but it will load a little faster[/color]
                  > since the[color=green]
                  >> system doesn't need to locate and open the referenced assemblies.[/color]
                  >
                  > Do you mean that the C# compiler isn't smart enough not to insert code
                  > to load assemblies that aren't used by the code? I would have thought
                  > that either the compiler / CLR would load assemblies on "first use", so
                  > if you don't call them, they don't get loaded, or at least not build in
                  > code to load assemblies that aren't used in the code.
                  >
                  > The "first use" method would seem the most efficient: what if your
                  > program uses some large assembly but the user never takes an action
                  > that would cause it to be called? Would the CLR load it when your app
                  > starts up, anyway, even if the user never did anything that would
                  > require that assembly? Now I'm curious. :)
                  >[/color]

                  You are right.
                  Only assemblies that are 'referenced' in code (have entries in the
                  assembly's Metadata) can be loaded implicitely. Assemblies that are included
                  in your project settings (used by the compiler) but aren't referenced in
                  code are simply ignored by the compiler, they aren't included in the
                  Metadata and cannot be loaded implicitely.

                  Willy.


                  Comment

                  • Bruce Wood

                    #10
                    Re: Which referenes being used?

                    When are the assemblies loaded? When the application starts up, or upon
                    first call?

                    This may make a difference, for example, in an application that
                    produces reports and can produce graphs. The graphing assembly might be
                    some monster beast that can produce pie charts, bar charts, line
                    graphs, etc. If the user never requests a graph, does the assembly get
                    loaded anyway (since it is referenced by the main program assembly)? Or
                    does the CLR wait until the first attempt to call something in the
                    assembly before it loads it? I would hope the latter.

                    Comment

                    • Willy Denoyette [MVP]

                      #11
                      Re: Which referenes being used?


                      "Bruce Wood" <brucewood@cana da.com> wrote in message
                      news:1115928558 .493681.174930@ f14g2000cwb.goo glegroups.com.. .[color=blue]
                      > When are the assemblies loaded? When the application starts up, or upon
                      > first call?
                      >
                      > This may make a difference, for example, in an application that
                      > produces reports and can produce graphs. The graphing assembly might be
                      > some monster beast that can produce pie charts, bar charts, line
                      > graphs, etc. If the user never requests a graph, does the assembly get
                      > loaded anyway (since it is referenced by the main program assembly)? Or
                      > does the CLR wait until the first attempt to call something in the
                      > assembly before it loads it? I would hope the latter.
                      >[/color]

                      It's the latter, assemblies are demand loaded at first call.

                      Willy.



                      Comment

                      • Brett

                        #12
                        Re: Which referenes being used?


                        "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                        news:uUDZDyyVFH A.2128@TK2MSFTN GP14.phx.gbl...[color=blue]
                        >
                        > "Bruce Wood" <brucewood@cana da.com> wrote in message
                        > news:1115925717 .986868.169760@ g43g2000cwa.goo glegroups.com.. .[color=green][color=darkred]
                        >>>> Will removing the unused reference shrink the overall assembly size?[/color]
                        >>
                        >>[color=darkred]
                        >>> Not much if any size difference, but it will load a little faster[/color]
                        >> since the[color=darkred]
                        >>> system doesn't need to locate and open the referenced assemblies.[/color]
                        >>
                        >> Do you mean that the C# compiler isn't smart enough not to insert code
                        >> to load assemblies that aren't used by the code? I would have thought
                        >> that either the compiler / CLR would load assemblies on "first use", so
                        >> if you don't call them, they don't get loaded, or at least not build in
                        >> code to load assemblies that aren't used in the code.
                        >>
                        >> The "first use" method would seem the most efficient: what if your
                        >> program uses some large assembly but the user never takes an action
                        >> that would cause it to be called? Would the CLR load it when your app
                        >> starts up, anyway, even if the user never did anything that would
                        >> require that assembly? Now I'm curious. :)
                        >>[/color]
                        >
                        > You are right.
                        > Only assemblies that are 'referenced' in code (have entries in the
                        > assembly's Metadata) can be loaded implicitely. Assemblies that are
                        > included in your project settings (used by the compiler) but aren't
                        > referenced in code are simply ignored by the compiler, they aren't
                        > included in the Metadata and cannot be loaded implicitely.[/color]

                        Willy, where did you find this information? That's pretty good. I haven't
                        read anything about that. Appreciate any references you can provide.

                        Thanks,
                        Brett


                        Comment

                        • Willy Denoyette [MVP]

                          #13
                          Re: Which referenes being used?


                          "Brett" <no@spam.com> wrote in message
                          news:O4S1JazVFH A.2572@TK2MSFTN GP14.phx.gbl...[color=blue]
                          >
                          > "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                          > news:uUDZDyyVFH A.2128@TK2MSFTN GP14.phx.gbl...[color=green]
                          >>
                          >> "Bruce Wood" <brucewood@cana da.com> wrote in message
                          >> news:1115925717 .986868.169760@ g43g2000cwa.goo glegroups.com.. .[color=darkred]
                          >>>>> Will removing the unused reference shrink the overall assembly size?
                          >>>
                          >>>
                          >>>> Not much if any size difference, but it will load a little faster
                          >>> since the
                          >>>> system doesn't need to locate and open the referenced assemblies.
                          >>>
                          >>> Do you mean that the C# compiler isn't smart enough not to insert code
                          >>> to load assemblies that aren't used by the code? I would have thought
                          >>> that either the compiler / CLR would load assemblies on "first use", so
                          >>> if you don't call them, they don't get loaded, or at least not build in
                          >>> code to load assemblies that aren't used in the code.
                          >>>
                          >>> The "first use" method would seem the most efficient: what if your
                          >>> program uses some large assembly but the user never takes an action
                          >>> that would cause it to be called? Would the CLR load it when your app
                          >>> starts up, anyway, even if the user never did anything that would
                          >>> require that assembly? Now I'm curious. :)
                          >>>[/color]
                          >>
                          >> You are right.
                          >> Only assemblies that are 'referenced' in code (have entries in the
                          >> assembly's Metadata) can be loaded implicitely. Assemblies that are
                          >> included in your project settings (used by the compiler) but aren't
                          >> referenced in code are simply ignored by the compiler, they aren't
                          >> included in the Metadata and cannot be loaded implicitely.[/color]
                          >
                          > Willy, where did you find this information? That's pretty good. I
                          > haven't read anything about that. Appreciate any references you can
                          > provide.
                          >
                          > Thanks,
                          > Brett
                          >[/color]

                          1.. Applied Microsoft .NET Framework Programming - J. Richter
                          2.. Shared Source CLI Essentials - Stutz, Neward and Shilling
                          3.. Essential .NET: Volume 1 - Don Box
                          4.. Inside Microsof .NET IL Assembler - S Lidin
                          5.. The Common Language Infrastructure Annotated Reference - J.Miller, AW
                          6.. Compiling for the .NET Common Language Runtime (CLR) - Gough
                          7.. ECMA CLI Partition Specs http://msdn.microsoft.com/net/ecma/
                          8.. MSDN, MSDN Magazine, Microsoft CLR Team Blogs
                          http://blogs.msdn.com/default.aspx, Debugging experiences etc...
                          Willy.



                          Comment

                          • Brett

                            #14
                            Re: Which referenes being used?


                            "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                            news:O6ipPY5VFH A.2796@TK2MSFTN GP09.phx.gbl...[color=blue]
                            >
                            > "Brett" <no@spam.com> wrote in message
                            > news:O4S1JazVFH A.2572@TK2MSFTN GP14.phx.gbl...[color=green]
                            >>
                            >> "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                            >> news:uUDZDyyVFH A.2128@TK2MSFTN GP14.phx.gbl...[color=darkred]
                            >>>
                            >>> "Bruce Wood" <brucewood@cana da.com> wrote in message
                            >>> news:1115925717 .986868.169760@ g43g2000cwa.goo glegroups.com.. .
                            >>>>>> Will removing the unused reference shrink the overall assembly size?
                            >>>>
                            >>>>
                            >>>>> Not much if any size difference, but it will load a little faster
                            >>>> since the
                            >>>>> system doesn't need to locate and open the referenced assemblies.
                            >>>>
                            >>>> Do you mean that the C# compiler isn't smart enough not to insert code
                            >>>> to load assemblies that aren't used by the code? I would have thought
                            >>>> that either the compiler / CLR would load assemblies on "first use", so
                            >>>> if you don't call them, they don't get loaded, or at least not build in
                            >>>> code to load assemblies that aren't used in the code.
                            >>>>
                            >>>> The "first use" method would seem the most efficient: what if your
                            >>>> program uses some large assembly but the user never takes an action
                            >>>> that would cause it to be called? Would the CLR load it when your app
                            >>>> starts up, anyway, even if the user never did anything that would
                            >>>> require that assembly? Now I'm curious. :)
                            >>>>
                            >>>
                            >>> You are right.
                            >>> Only assemblies that are 'referenced' in code (have entries in the
                            >>> assembly's Metadata) can be loaded implicitely. Assemblies that are
                            >>> included in your project settings (used by the compiler) but aren't
                            >>> referenced in code are simply ignored by the compiler, they aren't
                            >>> included in the Metadata and cannot be loaded implicitely.[/color]
                            >>
                            >> Willy, where did you find this information? That's pretty good. I
                            >> haven't read anything about that. Appreciate any references you can
                            >> provide.
                            >>
                            >> Thanks,
                            >> Brett
                            >>[/color]
                            >
                            > 1.. Applied Microsoft .NET Framework Programming - J. Richter
                            > 2.. Shared Source CLI Essentials - Stutz, Neward and Shilling
                            > 3.. Essential .NET: Volume 1 - Don Box
                            > 4.. Inside Microsof .NET IL Assembler - S Lidin[/color]
                            Had to use the Amazon.uk site for this one.
                            [color=blue]
                            > 5.. The Common Language Infrastructure Annotated Reference - J.Miller, AW
                            > 6.. Compiling for the .NET Common Language Runtime (CLR) - Gough
                            > 7.. ECMA CLI Partition Specs http://msdn.microsoft.com/net/ecma/
                            > 8.. MSDN, MSDN Magazine, Microsoft CLR Team Blogs
                            > http://blogs.msdn.com/default.aspx, Debugging experiences etc...[/color]
                            Good stuff on the blogs.
                            [color=blue]
                            > Willy.
                            >[/color]
                            Here's a couple more that have good ratings and seem worthwhile:
                            Shared Source CLI Essentials
                            The C# Programming Language by Anders Hejlsberg

                            Great references. Thanks.

                            Brett


                            Comment

                            Working...