tags:

views:

116

answers:

1

I'm just starting out with postsharp/AOP. I want to make some instrumentation for C# to track the usage of some addins that I write for a peice of software.

I am trying to use the OnMethodBoundaryAspect class to take note of the values of some of the parameters when the method is called. Those parameters are types which are referenced in an external DLL.

When I add my attribute to the method, the project won't build, I get the following error

Error 2 Unhandled exception (2.0.5.1204, 64 bit, CLR 2.0, Release): PostSharp.CodeModel.AssemblyLoadException: Error while loading the assembly "C:\Program Files\Autodesk\Revit Structure 2011\Program\RevitAPI.dll": Could not load file or assembly 'revitapi, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

The REvitAPI.dll is the file with the type in it. I've also tested just adding the attribute to the project but not applying it to any methods, this also causes the error. So it appears its not related to the method parameter types itself, but merely the existence of this DLL.

Has anyone come across this issue before, or can anyone point me in the right direction of where to get some more info on this?

+1  A: 

This is a known issue with C++ dependencies.

The reason is that RevitAPI.dll is not pure MSIL, so it cannot be loaded by the native (faster) host.

A workaround is to mark this assembly as "ignored". You can do that by editing the csproj and adding:

<PropertyGroup>
  <PostSharpProperties>IgnoredAssemblies=RevitAPI</PostSharpProperties>
</PropertyGroup>

If this does not work (because there is no way for PostSharp to ignore the assembly), you have to force PostSharp to use the managed (slower) host:

<PropertyGroup>
  <PostSharpHost>Managed</PostSharpHost>
</PropertyGroup>
Gael Fraiteur