开发者

Unity Configuration and Same Assembly

开发者 https://www.devze.com 2022-12-13 06:23 出处:网络
I\'m currently getting an error trying to resolve my IDataAccess class. The value of the property \'type\' cannot be parsed. The error is: Could not load file or assembly \'TestProject\' or one of it

I'm currently getting an error trying to resolve my IDataAccess class.

The value of the property 'type' cannot be parsed. The error is: Could not load file or assembly 'TestProject' or one of its dependencies. The system cannot find the file specified. (C:\Source\TestIoC\src\TestIoC\TestProject\bin\Debug\TestProject.vshost.exe.config line 14)

This is inside a WPF Application project.

What is the correct syntax to refer to the Assembly you are currently in? is there a way to do this? I know in a larger solution I would be pulling Types from seperate assemblies so this might not be an issue. But what is the right way to do this for a small self-contained test project. Note: I'm only interested in doing the XML config at this time, not the C# (in code) config.

UPDATE: see all comments

My XML config:

<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
  </configSections>
  <unity>
    <typeAliases>
      <!-- Lifetime manager types -->
      <typeAlias alias="singleton"  type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias开发者_如何学Go alias="external" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="IDataAccess" type="TestProject.IDataAccess, TestProject" />
      <typeAlias alias="DataAccess" type="TestProject.DataAccess, TestProject" />
    </typeAliases>
    <containers>
      <container name="Services">
        <types>
          <type type="IDataAccess" mapTo="DataAccess" />
        </types>
      </container>
    </containers>
  </unity>
</configuration>


In unity 5.7

The section line should be like this

<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Unity.Configuration" />


This looks fine. Are you sure your assembly name is correct? Check the project preferences to make sure the name of your assembly is correct:

  1. Right click your project and click Properties
  2. Click on the Application tab on the left
  3. Look at the value of the "Assembly Name" field.

Sometimes if you've renamed your project, this field will still be the old value.

It's possible that this is not the issue at all, but it is the simplest thing to check. If you find that this is not the issue, reply to this and I'll post any other ideas I have.

Also, you might consider posting your sample as a .zip file so we can take a look at it.


I just had the same issue. this works for me : Turn "Copy local" to true in the properties of Microsoft.Practices.Unity. You should also add a reference to Microsoft.Practices.ObjectBuilder2 (Microsoft.Practices.Unity depends of it)

0

精彩评论

暂无评论...
验证码 换一张
取 消