0

How to use C# Code to List all Namespaces in .NetStandard Library 2.0 from within a .Net Standard Project.

This is the Code which gives Namspaces in netStandard Library is 0;

            foreach (AssemblyName fooAssemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
            {
                Assembly assembly = Assembly.Load(fooAssemblyName.FullName);
                var namespaces = assembly.GetTypes()
                    .Select(t => t.Namespace).Where(t => !string.IsNullOrEmpty(t))
                    .Distinct();
                int count = namespaces.Count();
                if (fooAssemblyName.Name == "netstandard")
                {
                    Console.WriteLine(count); // THIS GIVES 0 for .Net Standard Library
                }
            }
6
  • "...does not seem to work..." - this information is not really helpful. It does not say what exactly did not work, i.e. did you get any error messages anywhere, did you try to debug the issue to make sure that it actually does the intended thing. Commented Nov 25, 2019 at 7:01
  • Can't reproduce this problem. I guess you referenced the library but didn't actually use any class. Commented Nov 25, 2019 at 7:14
  • As i mentioned in the code, the Count() is 0. Which means there are No Namespaces for the. Net standard Commented Nov 25, 2019 at 7:21
  • I have updated the Code. please see now. Commented Nov 25, 2019 at 7:27
  • I am looking to get a list of all the namespaces in the netStandrad library. Commented Nov 25, 2019 at 7:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.