简体   繁体   English

使用Postsharp时在VS2012中编译c#项目时出错

[英]Error when compiling c# project in VS2012 when using Postsharp

I am currently working on a project where we were wanting to add PostSharp functionality. 我目前正在开发一个我们想要添加PostSharp功能的项目。

I have set up my Postsharp attribute as so 我已经设置了Postsharp属性

[Serializable]
public class NLogTraceAttribute : OnMethodBoundaryAspect
{
    private readonly string _logLevel;
    ILogger logger;

    public NLogTraceAttribute(string logLevel)
    {
        _logLevel = logLevel;

        logger = new Logger("TraceAttribute");
    }

    public override void OnEntry(MethodExecutionArgs args)
    {
        LogAction("Enter", args);
    }

    public override void OnExit(MethodExecutionArgs args)
    {
        LogAction("Leave", args);
    }

    private void LogAction(string action, MethodExecutionArgs args)
    {
        var argumentsInfo = args.GetArgumentsInfo();

        logger.Log(_logLevel, "{0}: {1}.{2}{3}", action, args.Method.DeclaringType.Name, args.Method.Name, argumentsInfo);
    }
}

and trying to use it as 并尝试将其用作

    [NLogTrace(NLogLevel.Debug)]

However when compiling the project I am getting the following error: 但是在编译项目时,我收到以下错误:

    Error   26  Cannot serialize the aspects: Type 'NLog.Logger' in Assembly 
    'NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' 
    is not marked as serializable.. 

Any help would be appreciated 任何帮助,将不胜感激

[NonSerialized]
public Logger logger;

Declaring the logger as marked above has solved the problem I was having 声明上面标记的记录器已经解决了我遇到的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#VS2012创建新文档时出现System.MissingMethodException错误 - System.MissingMethodException error when creating new document using C# VS2012 Windows Store Project-尝试从VS2012中的C#文件运行cmd命令时出现程序集引用错误 - Windows Store Project - Assembly reference error when trying to run cmd commands from a C# file in VS2012 在VS2012 C#项目中剪切和粘贴WinForms控件时保留事件处理程序分配? - Retain Event handler assignments when cutting and pasting WinForms controls in VS2012 C# project? 如何在C#项目中使用VS2012的自动HLSL编译? - How can I use VS2012's automatic HLSL compiling in a C# project? 如何在使用VS2012创建的Blend 4中编辑ac#project? - How to edit a c# project in Blend 4 that was created with VS2012? vs2012中使用C#的Razor MVC验证错误修复 - Razor MVC validation error fix with c# in vs2012 VS2012 C#SQL数据库错误-安装不正确? - VS2012 C# SQL database error - improperly installed? AutoComplete comboBox不建议何时将文本复制并粘贴到C#Winform VS2012中的comboBox中 - AutoComplete comboBox does not suggest when the text copied and pasted into comboBox in c# winform VS2012 调试Matlab生成的DLL时C#VS2012 vshost.exe崩溃 - C# VS2012 vshost.exe crashes when debugging Matlab generated DLL 使用VS2012在C#上进行错误的浮点转换 - Bad float conversion on C# using VS2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM