Re: Trouble with Custom PropertyAttribute -SerializationException with enum parameter
"Charlie Poole" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <006001c8324b$11ae22e0$85c8000a@FERRARI> |
Hi Jay, For this to work, you have to make sure that the data in the attribute itself is of a type that NUnit knows without loading your assembly. (Yes, NUnit has loaded your assembly in the test domain, but it is not loaded in the primary domain where the gui or console is running. You can think of the test domain as a sandbox.) I think the easiest way to do this is to have your own constructor, which sets the value of the property to the string name of the enum value. Charlie > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf > Of Walker Jay W > Sent: Thursday, November 29, 2007 12:39 AM > To: [email protected] > Subject: [Nunit-users] Trouble with Custom PropertyAttribute > -SerializationException with enum parameter > > > I'd like to take advantage of derived PropertyAttributes to > support Requirement Traceability in our unit tests based on > the examples at: > http://nunit.net/index.php?p=property&r=2.4.3 > <http://nunit.net/index.php?p=property&r=2.4.3> > > If I use the [Property(string, object)] syntax where object > is a system type such as string or int, I am able to execute > the tests. > EX: [Property("Traceability", "Requirement1")] > > However, my preference is to define a custom attribute to > take advantage of compile time type checking: > EX: [Traceability(Requirements.Requirement1)] > where Requirements is a public enum > > > When I attempt to execute the tests by loading the test > assembly in the nunit gui (nunit.exe v 2.4.3), I receive the > following error: > System.Runtime.Serialization.SerializationException: Unable > to find assembly 'PropertyTest, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=0ff96b337bb1c2da' > > Here is a partial stack trace: > > System.Runtime.Serialization.SerializationException... > Server stack trace: > at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyI > nfo.GetAss > embly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Ge > tType(Bina > ryAssemblyInfo assemblyInfo, String name) ... > at > System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& > msgData, Int32 type) > at NUnit.Core.TestRunner.get_Test() > at NUnit.Util.ProxyTestRunner.get_Test() > at NUnit.Util.TestLoader.LoadTest(String testName) > > > > I only receive the error when the CustomAttribute takes an > enum parameter (similar to the Priority example). If the > CustomAttribute takes an int parameter, it runs fine. I > noticed in the nunit source, there are no tests using > CustomAttributes with an enum parameter, although the website > example shows this as a valid case. I assume there is a > subtle error in my code. > > > Here is the source to reproduce the problem: > //begin > //referenced Nunit.framework.dll (v2.4.3). > //loaded into Nunit.exe (v2.4.3) with Load Project and > pointed directly to the PropertyTest.dll assembly //at which > time I received the exception before executing any tests. > > using System; > using System.Collections.Generic; > using System.Text; > using NUnit.Framework; > namespace PropertyTest > { > [TestFixture] > public class Class1 > { > [Test] > [Property("Severity", "Critical")] > public void SimplePropertyTest() > { /* ... */ } > [Test] > [Traceability(Requirements.Requirement1)] > public void CustomPropertySingleTest() > { /*...*/ } > [Test] > [Traceability(Requirements.Requirement2)] > [Traceability(Requirements.Requirement3)] > public void CustomPropertyMultipleTest() { /*...*/ } } > > public enum Requirements > { > Requirement1, > Requirement2, > Requirement3, > } > [AttributeUsage(AttributeTargets.Method, AllowMultiple = > true)] public class TraceabilityAttribute : PropertyAttribute > { public TraceabilityAttribute(Requirements level) > : base(level) > { > } > } > } > //end > > > Any help would be appreciated, > > Thanks, > > Jay > > > -------------------------------------------------------------- > ----------- > SF.Net email is sponsored by: The Future of Linux Business > White Paper from Novell. From the desktop to the data > center, Linux is going mainstream. Let it simplify your IT future. > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 > _______________________________________________ > Nunit-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/nunit-users > ------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4