标签: postsharp

PostSharp AssemblyLoadException Autofac

我正在建立一个新的解决方案,我想使用最新的Autofac(3.4)和PostSharp 3.1.42.在引用NuGet包后,我得到以下错误,我无法弄清楚发生了什么.我从未选择过Autofac 3.3.0软件包.

packages.config:

  <package id="Autofac" version="3.4.0" targetFramework="net451" />
  <package id="Autofac.Extras.Multitenant" version="3.1.1" targetFramework="net451" />
  <package id="Autofac.Mvc5" version="3.3.0" targetFramework="net451" />
  <package id="PostSharp" version="3.1.42" targetFramework="net451" />
Run Code Online (Sandbox Code Playgroud)

MSBuild日志:

Error   3   Unhandled exception (3.1.43.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'autofac, version=3.3.0.0, culture=neutral, publickeytoken=17863af14b0044da'. [Version mismatch]

============ PostSharp Assembly Loading Log ===================

LOG: Finding the assembly with binding identity 'autofac, version=3.3.0.0, culture=neutral, publickeytoken=17863af14b0044da'.

LOG: Found file 'D:\web\Project\packages\Autofac.3.4.0\lib\net40\Autofac.dll' with identity 'autofac, version=3.4.0.0, culture=neutral, publickeytoken=17863af14b0044da, processorarchitecture=msil'.

LOG: Reference mismatch for 'D:\web\Project\packages\Autofac.3.4.0\lib\net40\Autofac.dll' [VersionMismatch].

LOG: …
Run Code Online (Sandbox Code Playgroud)

.net c# postsharp autofac

2
推荐指数
1
解决办法
1941
查看次数

Postsharp 抛出 System.Runtime.InteropServices.COMException (0x8013141C):未找到强名称密钥容器。(HRESULT 异常:0x8013141C)

为将来需要解决相同问题的任何人添加问题

环境:Visual Studio 2017 或 2019
Postsharp 签名程序集时出现构建错误

MSBuild postsharptest.csproj /T:Rebuild /P:PostSharpTrace=StrongName /V:D /P:PostSharpHost=Native > postsharp.log

C:\ProgramData\PostSharp\4.0.41\bin.Release\postsharp.4.0-x86.exe obj\Debug\Before-PostSharp\PostsharpTest.exe /X:default /NoLogo /P:Output=C:\PostsharpTest\obj\Debug\PostsharpTest.exe /P:ReferenceDirectory=C:\PostsharpTest /P:Configuration=Debug /P:Platform=AnyCPU "/P:SearchPath=bin\Debug\|obj\Debug\|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\ " /P:IntermediateDirectory=obj\Debug\PostSharp /P:CleanIntermediate=False /P:MSBuildProjectFullPath=C:\PostsharpTest\postsharptest.csproj /P:SignAssembly=true /P:PrivateKeyLocation=Thycotic.snk /P:PrivateKeyContainer= /P:DelaySign= "/P:ResolvedReferences=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll|C:\PostsharpTest\packages\PostSharp.4.0.41\lib\net35-client\PostSharp.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /P:SymbolFile=bin\Debug\PostsharpTest.pssym /P:WriteWeavingSymbols=True /P:ConstraintVerificationEnabled=True /P:RuntimeVerificationEnabled=True /P:TargetFrameworkVersion=v4.5 /P:TargetFrameworkIdentifier=.NETFramework /P:TargetFrameworkProfile= "/P:TargetFrameworkMoniker=.NETFramework,v4.5" "/P:NativeFrameworkMoniker=.NETFramework,v4.5.1" /P:BindingMapsDirectory=C:\ProgramData\PostSharp\4.0.41\BindingMaps /P:PostSharpLibraryProfile= /P:AspectProviders= "/P:Language=C#" …
Run Code Online (Sandbox Code Playgroud)

msbuild code-signing postsharp

2
推荐指数
1
解决办法
879
查看次数

升级到VS 2010后,Team City构建失败

我有一个项目,目前使用VS 2010(可能使用MSBUILD v4.0)在我的开发机器上愉快编译,但它在Team City中的MSBUILD v3.5下运行(在基于Win 2003服务器w/.NET 2的VM上运行) ,3.5和4安装).该项目新升级到2010年,现在CI构建失败了.我用Google搜索了这一切并尝试了一切显而易见的事情(加上一些没有意义的事情)并且没有任何影响结果.

该项目失败,出现一系列错误,如下所示:

error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

解决方案中有许多其他项目使用System.Core,System.Data.Linq和System.Xml.Linq,它们似乎都没有问题地编译.有问题的项目是一个Web应用程序,它的配置/ system.web/compilation/assemblies部分中包含以下设置:

    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Run Code Online (Sandbox Code Playgroud)

在同一个文件中加上以下内容:

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
      <providerOption name="CompilerVersion" value="v3.5"/>
      <providerOption name="WarnAsError" value="false"/>
    </compiler>
  </compilers>
</system.codedom>
Run Code Online (Sandbox Code Playgroud)

有问题的项目是IIRC,我解决方案中唯一一个既是WebApplication也正在由PostSharp(v1.5)进行后期处理的项目.PostSharp在.csproj中配置如下:

<PropertyGroup>
  <DontImportPostSharp>True</DontImportPostSharp>
  <PostSharpUseCommandLine>True</PostSharpUseCommandLine>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" …
Run Code Online (Sandbox Code Playgroud)

postsharp visual-studio-2010 .net-3.5 teamcity-5.1

1
推荐指数
1
解决办法
1798
查看次数

如何排除构造函数被Namespace广泛方面击中

我刚开始使用Postsharp作为在项目上进行日志记录等的方法,并且遇到了一个我尚未解决的问题.

在我的项目中,我创建了我的LogAttribute,它正确地记录了我想要做的信息,例如参数进出方法.唯一的问题是它也为所有构造函数执行此操作,我不想记录.

有没有办法排除构造者被注销?

我的GlobalAspects.cs看起来类似于:

using PostSharp.Patterns.Diagnostics;
using PostSharp.Extensibility;

[assembly: TraceAttribute(AttributeTargetTypes = "myNamespace.toLog.*", AttributeTargetTypeAttributes = MulticastAttributes.Public, AttributeTargetMemberAttributes = MulticastAttributes.Public)]
Run Code Online (Sandbox Code Playgroud)

我的属性中的My OnEntry,OnSuccess和On Exception方法都是以下变体:

        StringBuilder output = new StringBuilder();
        output.Append("Entering: ");
        output.Append(this.methodName);

        for (int i = 0; i < args.Arguments.Count; i++)
        {
            output.Append("  Argument: " + i + " - ");
            output.Append(args.Arguments.GetArgument(i) ?? "null");
        }

        m_logger.Trace(output);
Run Code Online (Sandbox Code Playgroud)

aop postsharp

1
推荐指数
1
解决办法
853
查看次数

在VS2012中使用假货时发出PostSharp警告

我们最近更新到VS2012,并将PostSharp版本更改为3.0.26.通常这种组合工作正常,但我得到了我的单元测试项目的警告,如

模块" MyModule.Fakes.dll"不包含任何方面或其他转换.为了提高构建时性能,请考虑通过在项目中设置编译符号(也称为常量)"SkipPostSharp"来禁用此模块的PostSharp,或者设置MSBuild属性"SkipPostSharp = True".

现在我通常可以通过相应地更改项目设置来禁用此警告(SkipPostSharp = True),但我已经为包含单元测试的MyProjectTest项目完成了此操作.

当我在文件夹中添加<SkipPostSharp>True</SkipPostSharp>MyModule.FakesFakes文件时,关于PostSharp的警告消失了,但是,我收到另一条错误消息:

在命名空间"元素"正版正货" http://schemas.microsoft.com/fakes/2011/ "具有无效的子元素"SkipPostSharp"命名空间" http://schemas.microsoft.com/fakes/2011/ ".期望的可能元素列表:命名空间" http://schemas.microsoft.com/fakes/2011 "中的"StubGeneration,ShimGeneration,Compilation ".

更新

我也尝试编辑fakes.xsd文件并添加一个额外的SkipPostSharp元素,但是a)这仍然不被Visual Studio识别为有效元素和b)我不确定这是否是正确的方法.

任何想法如何摆脱这些警告?

postsharp microsoft-fakes visual-studio-2012

1
推荐指数
1
解决办法
700
查看次数

我如何使用简单的面向方面的概念来处理异常处理而不需要 postsharp?

我想使用 AOP 来处理控制台应用程序中的错误异常。(这不是 MVC,我使用属性花瓶编程来处理 MVC 中的错误,但这是控制台应用程序)我的代码如下:(如果发生错误,它应该在我的属性端代码中抛出错误)

 [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class HandleError : Attribute
{
     public HandleError(string description)
    {
        try
        {
            this.Description = description;
        }
        catch (Exception)
        {

            throw;
        }

    }
    public string Description { get; set; }


}
Run Code Online (Sandbox Code Playgroud)

这将从我的方法中调用:

   [HandleError("Error occurs here")]
    public static void MyMethod(string data)
    {
        throw new Exception();
Run Code Online (Sandbox Code Playgroud)

实际上; 我想使用 AOP 来处理我的方法内的异常。如果发生错误,我必须调用属性。但如何呢?(请不要提供 postsharp,它需要钱。但我也开放开源)顺便说一句;为什么这不容易,我不明白。

c# oop aop design-patterns postsharp

1
推荐指数
1
解决办法
1906
查看次数

找不到类型的序列化程序

我已经构建了一个方面,它使用我自己的库中的一个类来工作。为了有用,该类需要可序列化,但是当让 PostSharp 做它的事情时,我收到了这个错误:

PostSharp 3.0 [3.0.35.0, 64 bit, CLR 4.5, Release] - Copyright (c) SharpCrafters
 s.r.o., 2004-2012.

POSTSHARP : error LA0001: Cannot serialize the aspects: Cannot find a serializer
 for type 'NextGen.Framework.Managers.LogMgr.NxLogMgr'..
POSTSHARP : message PS0122: Details of the previous error or warning:\nPostSharp
.Serialization.PortableSerializationException: Cannot find a serializer for type
 'NextGen.Framework.Managers.LogMgr.NxLogMgr'.
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Ge
tObjectInfo(Object obj)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Wr
iteObjectReference(Object value, Boolean writeInitializationDataInline)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Wr
iteValue(Object value, SerializationIntrinsicType intrinsicType, Boolean …
Run Code Online (Sandbox Code Playgroud)

.net vb.net aop postsharp

0
推荐指数
1
解决办法
821
查看次数