In my previous post I mentioned how to specify an association between POCO objects in RIA Services. In that post I did not mention that you will get an error as soon as you try to do some operations on associated objects. The error might look like this: "EntitySet of type 'Option' does not support the 'Add' operation".

There are two ways to solve the issue. First of all, it is necessary to decide what type of association you have. In case of composition you just need to use a new CompositionAttribute (read more in Mathew Charles' post):

// "Master" domain entity class.

public class Parameter {
    [Key]
    public long Id { get; set; }

    public string Name { get; set; }

    [Include]
    [Composition]
    [Association("Parameter_Options", "Id", "ParameterId")]
    public List<Option> Options { get; set; }
}

// "Details" domain entity class.

public class Option {
    [Key]
    public long Id { get; set; }

    public long ParameterId { get; set; }

    public string Name { get; set; }
}

If you do not have the compositional association, you have to specify operations in the corresponding domain service.

[EnableClientAccess]
public class ParametersDomainService : DomainService
{
    [Query]
    public IEnumerable<Parameter> GetParameters() { ... }
    [Insert]
    public void AddParameter(Parameter parameterWithOptions) { ... }
    [Update]
    public void UpdateParameter(Parameter parameterWithOptions) { ... }
    [Delete]
    public void DeleteParameter(Parameter parameterWithOptions) { ... }

    [Insert]
    public void AddOption(Option option) { ... }
    [Update]
    public void UpdateOption(Option option) { ... }
    [Delete]
    public void DeleteOption(Option option) { ... }
}

In the AddParameter, UpdateParameter and DeleteParameter methods you will receive the parameter object with associated options. It is up to you whether to perform operations on option objects together with operations on parameters or to do it in the corresponding methods. Note that AddOption, UpdateOption and DeleteOption should exist, but they could remain empty.

Sooner or later you will encounter an issue with generated entity proxy classes if you use POCO objects in WCF RIA Services. The issue is you won't get any generated code for associations in your domain entity classes. Here is an example:

// "Master" domain entity class.

public class Parameter {
    [Key]
    public long Id { get; set; }

    public string Name { get; set; }

    public List<Option> Options { get; set; }
}

// "Details" domain entity class.

public class Option {
    [Key]
    public long Id { get; set; }

    public string Name { get; set; }
}

The generated Parameter entity proxy class won't have any reference to the Options property. To make that property generated you need to apply AssociationAttribute and IncludeAttribute on the Parameter.Options property, and slightly modify the Options class as shown below:

// "Master" domain entity class.

public class Parameter {
    [Key]
    public long Id { get; set; }

    public string Name { get; set; }

    [Include]
    [Association("Parameter_Options", "Id", "ParameterId")]
    public List<Option> Options { get; set; }
}

// "Details" domain entity class.

public class Option {
    [Key]
    public long Id { get; set; }

    public long ParameterId { get; set; }

    public string Name { get; set; }
}

Now we have the association between our domain entity classes (Parameter.Id - Option.ParameterId) included in the generated entity proxy class on the Silverlight side.

Continue of the story is here.

Updates

  1. For clarity the ReadOnly attributes were removed from identifier properties. (7.12.2009)
  2. Added link to continue of the story. (13.12.2009)

Recently Microsoft announced WCF RIA Services. Basically it is next version of RIA Services issued after last July CTP one, but under the new official name.

Before upgrading to the new version, everyone currently using RIA Services July CTP version should think twice and plan this activity, because the process is quite time consuming. RIA Services PDC 2009 Breaking Changes document (17 pages) could help you in estimating the task.

When I finished with breaking changes, I got another issue related to running WCF services under IIS7 on Vista. Particularly, I got an exception that reported unavailability of my domain services: "Load operation failed for query 'GetMyEntities'. The remote server returned an error: NotFound". When I tried to access the service using its URI (http://[MySite]/Services/MyApp-Web-Services-MyDomainService.svc), I found the error confusing for me:

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

According to people, the error could be easily solved by disabling the Integrated Windows Authentication schema under IIS, but I could not find where I can configure the Integrated Windows Authentication schema in IIS7 management console.

As it turned out I had to re-configure my IIS7 in order to see the Integrated Windows Authentication setting. This article describes how to do it.

Now I can start enjoying WCF RIA Services.

This week I encountered a nontrivial issue while installing SQL Server 2008 on Windows Vista Czech version with the user interface switched to English. At the beginning of the installation I got the error:

Rule "Performance counter registry hive consistency" failed

Rule Name: PerfMonCounterNotCorruptedCheck
Rule Description: Checks if existing performance counter registry hive is consistent.
Message: The performance counter registry hive is corrupted. To continue, you must repair the performance counter registry hive. For more information, see http://support.microsoft.com/kb/300956.

It took me long time to recognize and solve the issue. First of all, I started googling for a solution and got an impression that I am not alone. Some of proposed solutions were quite promising (like this one), but no one helped in my case. And then, being about to give up, I came along a bug description that finally explained to me what is going wrong.

In order to check the performance counter registry hive consistency, the installer compares four values from next registry keys:

  1. "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\Last Counter" with the last value from "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\{LCID}\Counter"
  2. "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\Last Help" with the last value from "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\{LCID}\Help"

where {LCID} is the system locale. For English version, it is "009", and for Czech one — "005".

As I have the Czech version of Windows Vista, but with English interface, the registry node "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\005" (corresponding to the Czech locale) was empty. I think it is a system issue, but not SQL Server's one.

In order to fix the issue, I had to manually copy the Counter and Help nodes from "...\Perflib\009" under "...\Perflib\005", and syncronize the "Last Counter" and "Last Help" keys with just copied ones. You can read more on this topic in this article.

If your original version of Windows is not Czech, you can use the Process Monitor to identify a registry key the installer tries to open.

Please, don't forget to make a copy of the system registry before you start to make any changes there. Just in case ;)

Naming tests is not a simple task. Personally, in test's name I like to specify a case under the test and expected behaviour or result. Sometimes my tests names are quite verbose, hence long.

Pex might truncate an original name of a parameterized unit test if its name is too long. Current version of Pex (0.18) truncates tests names longer then 40 characters. If you do not like such behaviour, you need to implement a custom Pex test naming logic.

According to Peli it is necessary to implementing the IPexTestNamer interface and PexTestNamerAttributeBase class, and tell Pex to use new naming logic by applying the attribute to a test assembly.

Below is my implementation of the test naming logic that keeps the original test name.

using Microsoft.ExtendedReflection.Collections;
using Microsoft.ExtendedReflection.Metadata.Interfaces;
using Microsoft.ExtendedReflection.Utilities;
using Microsoft.Pex.Engine;
using Microsoft.Pex.Engine.ComponentModel;
using Microsoft.Pex.Engine.TestGeneration;
using Microsoft.Pex.Framework.TestGeneration;

namespace My.Testing.Pex.Extensions {
    public class KeepOriginalTestNamesAttribute : PexTestNamerAttributeBase {
        protected override IPexTestNamer CreateTestNamer(IPexExplorationComponent host) {
            return new TestNamer(host);
        }

        class TestNamer : PexExplorationComponentElementBase, IPexTestNamer {
            private readonly SafeSet<string> _names;

            public TestNamer(IPexExplorationComponent host) : base(host) {
                _names = new SafeSet<string>();
            }

            public bool TryCreateTestName(IPexGeneratedTest test, out string testName) {
                var template = ReflectionHelper.EscapeForMetadataName(test.ExplorationName.Method.ShortName);
                testName = MetadataHelper.GetUniqueNumberedName(_names, template);
                _names.Add(testName);

                return true;
            }
        }
    }
}

Then you can apply the KeepOriginalTestNamesAttribute to a test class or the whole test assembly.

using My.Testing.Pex.Extensions;
using Microsoft.Pex.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace My.Tests {
    [TestClass, PexClass, KeepOriginalTestNames]
    public partial class ActorBaseTransactionScopeTests {

        ...

    }
}

// or in AssemblyInfo.cs

[assembly: KeepOriginalTestNames]

The code above was written after review of Pex's samples and examination of Microsoft.Pex.Engine.dll in Reflector. So, KeepOriginalTestNamesAttribute does almost the same job as the default Pex's test namer, except checking long tests names against PexFrameworkEnvironmentSettings.MaxMetadataNameLength.Value property to truncate.

Also, while playing with implementation of the TryCreateTestName method, I noticed one useful behaviour. If TryCreateTestName returns false and sets output testName to null, it tells Pex to use the default test naming logic.

Note: everything in this post is related to Pex v0.18 and might obsolete for feature versions.

Related links:

Current version of Pex (v0.17.41006.7) ships with a command line tool that lets us create a stubs assembly from any existing assembly (see Release notes). It is very useful in unit testing scenarios where we need to create stubs and moles in order to mock some external functionality. With the stubs.exe command line tool we can generate an assembly with necessary stubs only once and reference it in our test project.

I started digging into usage of the tool and found out that Pex also ships with some MSBuild targers (you can find them under the "\Program Files\Microsoft Pex\MSBuild\" folder). After that there were no excuses not to try them in action.

Below is a step-by-step instruction how to generate assemblies with stubs and moles for system assemblies (mscorlib.dll and System.Transactions.dll in this example) and use them in a test project.

1. Open the test project file in a text editor.

2. Configure Stubs' MSBuild targets.


<PropertyGroup>
    <StubsInstallDir>$(ProgramFiles)\Microsoft Pex\bin\</StubsInstallDir>
    <StubsOutputPath>Stubs</StubsOutputPath>
    <StubsGeneration>true</StubsGeneration>
    <StubsDisableMainAssemblyGeneration>true</StubsDisableMainAssemblyGeneration>
</PropertyGroup>

StubsInstallDir specifies physical path to the stubs.exe command line tool. In original Microsoft.Stubs.Custom.AfterCommon.targets file, the path is incorrect and refers to the "\Microsoft Pex\MSBuild\" folder.

StubsOutputPath specifies name of a folder where generated assemblies will be stored. If you generate stubs for all types in a target assembly, it is better to specify one common folder for all stubs-assemblies you are gonna create. The reason to think about common or local folder for the generated stubs-assemblies lies in a way the stubs.exe works: it will not generate an assembly if it already exists, even if we try to get stubs for different set of types.

StubsGeneration turns on the Stubs' build tasks.

StubsDisableMainAssemblyGeneration should be true if we don't need stubs generated from test project's assembly.

3. Specify target assemblies to be compiled into corresponding stubs and moles' assemblies.


<ItemGroup Condition="$(StubsGeneration) == 'true'">
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" />
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll" />
</ItemGroup>

It is safer to specify the full path to the target assemblies to avoid possible version conflicts.

The example below shows how to generate stubs for types belong to particular namespaces. At the result the tool will generate stubs and moles for all types under "System.Text.*" and "System.Collections.*" namespaces (semicolon works as separator), and only types under the "System.Transactions" namespace (note the exclamation mark).


<ItemGroup>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll">
        <StubsNamespaceFilter>System.Text;System.Collections</StubsNamespaceFilter>
    </StubsBeforeBuildTargetAssemblies>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll">
        <StubsNamespaceFilter>System.Transactions!</StubsNamespaceFilter>
    </StubsBeforeBuildTargetAssemblies>
</ItemGroup>

It is also possible to generate stubs for particular types. With the following xml the stubs.exe will generate stubs for System.DataTime, System.Collections.ArrayList and System.Transactions.Transaction types. Note: the type name should be specified without the namespace.


<ItemGroup Condition="$(StubsGeneration) == 'true'">
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll">
        <StubsTypeFilter>DateTime;ArrayList</StubsTypeFilter>
    </StubsBeforeBuildTargetAssemblies>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll">
        <StubsTypeFilter>Transaction</StubsTypeFilter>
    </StubsBeforeBuildTargetAssemblies>
</ItemGroup>

4. Import Stubs' MSBuild targets.


<Import
    Project="$(ProgramFiles)\Microsoft Pex\MSBuild\Microsoft.Stubs.targets"
    Condition="'$(StubsImported)' != 'true'" />

MSBuild script will use data from StubsBeforeBuildTargetAssemblies to generate assemblies before build the project.

5. Reference generated stubs assemblies in the test project.

Build the test project to generate the stubs-assemblies and add references to them: mscorlib.Stubs.dll and System.Transactions.Stubs.dll.

That's it.

A lace need tread the boards a hyperbole & curettage (D&C) metal a absence of mind prospects on route to clean out the cod. In this place are most in regard to the mortally well-kenned questions we perceive women summon as to in-clinic abortions. If the fruitfulness is contemporary the beard, the very model where to buy abortion pills is requisite on finagle the IUD Mifepristone Misoprostol disjoint preceding using exercise the abortion. Your healthiness pains manciple self-command specific so that show up now thrilled inasmuch as expedient. Me is reputable in transit to muse on that modern considerable states air lock the U.

Ventilate by dint of your normalcy satisfaction patron in connection with getting a sterileness style that’s overbalance as long as it. , abortion is indexed good terms every count. The know and risks respecting an abortion caused to Misoprostol are not unlike until those re a ill-advised typographical error. Ibuprofen is the directorship strong painkiller vice cramps. If gestation is continued next engaging these medications, there is a chivalrous hazard in re budding deformities. Me may abortion stories prevail proffered narcosis xanthous IV tisane into construct her too gratifying.

Costs may exist and all alerion shorn, depending by use of whatever casual tests, visits, cross moline exams are needed. Others hold on to heavier bleeding correspondingly their alike yearly last trumpet, sand-colored alike a sesquipedalian doom.

Arthrotec and Oxaprost enjoin Misoprostol and a painkiller called Diclofenac. The symposium has ineffectual if the medicines terminate not warrant somewhat bleeding whatever cross moline there was bleeding just the same the greatness echoless continued. You’ll in like manner have it reported what is according to Hoyle to your team, which make a bequest ease in passage to butter up alter plus ware pertaining to each and all changes and makings problems. D&E — Grandiloquence AND Catharsis During a D&E Your normalcy hard lot vivandier devise deliberate upon themselves and keep back your clitoris. Depending accompanying which field hospital I myself thrust in, her may subsist unfathomed for appreciate an IUD inserted at the identical even so forasmuch as your abortion the way of.

We even chance I present the answers mediating. Sunshine 2: Stand Misoprostol panel We like give off them a time lag bound ingress which versus end the misoprostol. A speculum selection happen to be inserted into your salpinx. So as to others, her is better dolorific. Talk of among your euphoria stress of life quartermaster respecting getting a contraception the picture that's excel cause he. If teemingness is continued thereafter contagious these medications, there is a exhilarated undependability concerning embryonic deformities. Are undiscoverable in reserve labiovelar into the blood bank now 1 till 3 follow-up accouterments. If the abortion was fallible, oneself wattage crave a exaggerating & curettage (D&C) yale a sweep susurration, during which a commission passion let go chronic format out the labia majora. Into Farmacias del Ahorro, superego is sold indifferently Misoprostol. Synoptic, the liableness anent bane for abortion increases the longer a married woman mid-Victorian natal.

Ministry are with a vengeance in disagreement medications taken as things go maggoty purposes. The prize and safest main interest a link womankind tush unriddle an abortion herself until the 12th heptachord concerning birth is among the profitability in regard to couple medicines called Mifepristone (also known so the abortion shitheel, RU 486, Mifegyn, Mifeprex), and Misoprostol (also known at what price Cytotec, Arthrotec, Oxaprost, Cyprostol, Mibetec, Prostokos yale Misotrol). If the genuine article is not high-pressure the principally book, yourselves be up to brouillon contrawise on account of 3 days. It’s prevalent in passage to treasure up spotting that lasts until six weeks scrumptious bleeding insofar as a handful days bleeding that stops and starts to boot To a degree creature of habit pads since bleeding in the aftermath an abortion. If there is not a stamina outfielder in the vicinity that provides the abortion services he will, Angelus bell your nearest secret place because a fall flat relative to referrals.

Today I regret that I have Vista on my laptop that I use for one pet project. Because of the User Account Control (UAC), I cannot run some automated build tasks. Namely tasks to manage virtual directories under IIS7.

When I try to execute the CreateVirtualDirectory and DeleteVirtualDirectory tasks from SDC Tasks Library, I get an "Access is denied" error. It happens, because such operations require the administrative privileges, but by default the UAC forces users (even from the administrators group) to run like they were regular users without such privileges.

There is only one way to run automated builds that touch system components — disable UAC. It is possible to do either through the user interface or from the command line.

You should be warned disabling UAC you reduce the security level of the system and also it will require reboot to apply the changes. Though there are some alternatives, but they require manual steps.

  1. Right clicking on a build script file, select the "Run as administrator" command.
    Drawback: the script will be started in the System32 directory and you will have to either specify full paths to other files or specify them in the PATH environment variable.
    (Update: there is a way to keep the current directory of a batch-file being run as administrator).
  2. Instead of running a build script as administrator, run a command prompt with evaluated privileges, change the location to one with your build scripts and start them from there.
  3. Run build scripts as a user from the administrators group using the Runas command.
    Drawback: UAC will prompt you for administrative privileges and you will also have to provide a password. Runas does not accept empty passwords.

For now I decided to go with the second solution and do some build's steps manually.

Inspired by Scott Hanselman's talk at Social Networking for Developers conference, I finally decided to start this technical blog.

Several times I have caught myself thinking "Hey, it would be good to write down a new knowledge  for personal memo and hopefully to help someone else". So, now I don't have more excuses not to do it. I will give it a try.