首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PostSharp和StructureMap

PostSharp和StructureMap
EN

Stack Overflow用户
提问于 2014-03-08 17:51:18
回答 1查看 344关注 0票数 1

所以我读了达斯汀·戴维斯的有趣文章,决定自己用PostSharp 2.1.7.30和StructureMap 2.6.4.1试一试。

代码语言:javascript
复制
using System;
using PostSharp.Aspects;

namespace StructureMap
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            ObjectFactory.Initialize(x => { 
                x.For(typeof (IDbFind)).Use(typeof (DbFind)); });
            var w = new Worker();
            var f = w.Finder;
        }
    }

    internal class Worker
    {
        [IoCResolution] private IDbFind finder;
        public IDbFind Finder
        {
            get { return finder; }
        }
    }

    internal class DbFind : IDbFind
    {
    }

    internal interface IDbFind
    {
    }

    [Serializable]
    public class IoCResolution : LocationInterceptionAspect
    {
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (args.Value == null)
            {
                object obj = ObjectFactory.GetInstance(
                    args.Location.PropertyInfo.PropertyType);
                args.Value = obj;
                args.ProceedSetValue();
            }
        }
    }
}

不幸的是,在执行过程中,我得到了以下错误:

代码语言:javascript
复制
{"The type initializer for '<>z__Aspects' threw an exception."}

但内在的例外是:

代码语言:javascript
复制
{"Could not load file or assembly 'StructureMap, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The 
located assembly's manifest definition does not match the assembly reference. 
(Exception from HRESULT: 0x80131040)":"StructureMap, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null"}

FusionLog:

代码语言:javascript
复制
=== Pre-bind state information ===
LOG: DisplayName = StructureMap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Scratch/StructureMap/StructureMap/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : PostSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Scratch\StructureMap\StructureMap\bin\Debug\StructureMap.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Scratch/StructureMap/StructureMap/bin/Debug/StructureMap.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

知道我可能做错了什么吗?

5分钟后更新:,我是个白痴.这将教会我不要像调用第三方DLL一样调用我的命名空间。在将命名空间更改为StructureMapPlay之后,它就可以正常工作了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-08 18:00:22

在代码和项目属性中将命名空间更改为StructureMapPlay。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22272870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档