|
|
|
Community Member
|
|
Using the following code I get different build results sometimes even when building the same exact code twice in a row. Are there some kind of dependencies that I need to be specifying an order for somewhere?
I have a solution that contains two projects each containing one file of code. The first project contains the following code:
using System; using System.Collections.Generic; using PostSharp.Laos; using Microsoft.SqlServer.Management.Common;
namespace SMT.Tools.Aspects { public class ConnectionManager { //static Dictionary<string, ServerConnection> _connections = new Dictionary<string, ServerConnection>(); public static void Connect(string key){ //_connections[key].Connect(); } }
[Serializable()] [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public sealed class ConnectionHandlerAttribute: OnMethodBoundaryAspect { public ConnectionHandlerAttribute(string conn) { ConnectionManager.Connect(conn); } } }
The second project contains contains a reference to the .dll file that gets put in the bin/debug directory after the first project gets built. It contains the following code:
using SMT.Tools.Aspects;
namespace SMT.Testing.ConnectionManager {
public class ExceptionMaker { static void Main() { }
[ConnectionHandler("abc")] public ExceptionMaker() { } }
}
You'll notice a couple lines of code commented out in the first file. Everything compiles fine like this. Once you uncomment out the two lines it may or may not compile. If it does compile, then you can try to compile again (w/o making any changes whatsoever) and it will not compile. Then if you comment out both lines it still will not compile. Then if you try to compile again with the lines still commented out it will compile.
Very strange.
|
|
|
|
|
Community Member
|
|
OK, I figured out why the compiler is going back and forth on whether or not it wants to compile and I feel kind of dumb about not realizing what was earlier. It was compiling both projects at the same time and the second project was grabbing the old .dll before the new one was compiled.
However, this just puts it back to square one because the first project will compile just fine w/ or w/o those 2 lines commented out. But the second project will not compile if those lines haven't been commented out.
This was my attempt to pass information to the aspect since I can't pass variables to the attribute. Is there something intrinsically wrong with what I'm doing here that prohibits it from working, or is this a bug in Post Sharp?
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
You can pass only constants to custom attributes. This is a constraint of the .NET Framework.
-g
|
|
|
|