Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:24:18+00:00 2026-06-01T14:24:18+00:00

We typically only reference Microsoft.Practices.Unity.dll in our applications. We’re only using basic capabilities, and

  • 0

We typically only reference Microsoft.Practices.Unity.dll in our applications. We’re only using basic capabilities, and this works fine. In one application, the act of using reflection is causing Unity to require another DLL.

For example, create a console app and reference only Microsoft.Practices.Unity (file version 2.0.414.0). Enter the following code and run it:

class Program
{
    static void Main()
    {
        using (var container = new UnityContainer())
        {
            container.RegisterType<IDoSomething, ConcreteDoSomething>();

            var thing = container.Resolve<IDoSomething>();

            thing.DoSomething();
            Console.WriteLine();

            LoadSchemaLoaders();
        }
    }

    public static void LoadSchemaLoaders()
    {
        var type = typeof(ISchemaLoader);

        try
        {
            // Get all loaded assemblies, including Unity.
            // Get all of the types.
            // Filter for types that ISchemaLoader (custom type) can be assigned from.

            var types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(c => type.IsAssignableFrom(c) && c.IsClass && !c.IsAbstract && !c.IsGenericParameter);

            Console.WriteLine("Got here...");

            types.FirstOrDefault();
        }
        catch (ReflectionTypeLoadException ex)
        {
            Console.WriteLine(ex.Message);

            foreach (Exception exSub in ex.LoaderExceptions)
            {
                Console.WriteLine(exSub.Message);
            }
        }
    }
}

public interface IDoSomething
{
    void DoSomething();
}

public class ConcreteDoSomething : IDoSomething
{
    public void DoSomething()
    {
        Console.WriteLine("Something!");
    }
}

public interface ISchemaLoader {}

On my machine, the output is:

Something!

Got here...
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Now comment out the line

LoadSchemaLoaders();

Run it again and it works.

This is a simplified version of production code. The production code is actually dynamically loading custom types that implement an interface. As soon as we introduced Unity, the code threw an exception. But Unity types can’t implement our interface!

I don’t understand how simply reflecting over the assembly is causing the core Unity assembly to require another dependency.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:24:20+00:00Added an answer on June 1, 2026 at 2:24 pm

    A type in the Unity assembly from an interface defined in Microsoft.Practices.ServiceLocation (probably IServiceLocator).

    The compiler doesn’t require your application to reference that dll directly…but reflecting over the System.Type object will try to load the dll referenced by Unity.

    The reason this only happens when you reflect over the assembly is because Unity probably doesn’t load the type that references Microsoft.Practices.ServiceLocation under normal circumstances.

    As a work-around, you could enclose your Assembly.GetTypes() call in a try/catch block.

    Alternatively, if you put the Microsoft.Practices.ServiceLocation dll in a location where your application can find it, that should resolve the issue as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've typically done this using edmx's but this time in order to use cascading
We use log4net in all of our (many) in-house applications. We typically do what
I typically work on small-sized projects that involve only 2-3 people working on the
Typically you will find STL code like this: for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter
For the purposes of this question, I am interested only in Standard-Compliant C++, not
I've got a pretty basic question about how to start using Castle Windsor. I've
Wolfram site states that typically only 4 cores are used with its Parallel feature.
Here http://www.cplusplus.com/reference/stl/set/ I read that std::set in C++ is typically implemented as a tree
all: this is quoted from Effective C++ 3rd editiion const_cast is typically used to
I have a simple web site built with asp.net. It typically only has 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.