English 中文(简体)
Unity Configuration and Same Assembly
原标题:

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:SourceTestIoCsrcTestIoCTestProjectinDebugTestProject.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 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)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签