Valid XHTML 1.0!

Valid CSS!

Powered by PHP

Get FireFox

1&1 Internet

Archived News

.NET Service Reference and specified properties for optional elementsThursday 22nd October 2015
When you generate a Service Reference in Visual Studio for a web-service, you can often find a bunch of xxxSpecified boolean properties. These are from optional XML elements as per the service contract / WSDL.

For example, consider this XSD definition for a structure:
<xs:element name="MyObject">
<xs:element name="Date" type="xs:dateTime" minOccurs="0" maxOccurs="1" />

The service/WCF proxy will generate a class that looks a bit like this:

public partial class MyObject : object, INotifyPropertyChanged {
private DateTime dateField;
private bool dateFieldSpecified;
public DateTime Date {
get { return this.dateField; }
set {
this.dateField = value;
public event PropertyChangedEventHandler PropertyChanged;

I've simplified the generated code a bit. The important thing here is the "Specified" property that is generated. This happens when a minOccurs="0" is in the service XSD. It's the only clear way to tell whether an optional element was sent or not. Personally, I'd like to see an option in the Service Reference Configuration to allow this to be manifested as Nullable<>, but there isn't.

This proves a bit of a coding problem when setting these values for an outgoing request. Simply setting myObjectInstance.Date = DateTime.Now; wouldn't work - whilst the property is set, the Specified co-property is still left as the default "false". You can go and specify each of these individually when you set the data value.

This in turn though is even more problematic when you're doing something like model-binding with MVC. Assume your object is the parameter in a controller method and the values are being populated by the results of a HTML form post - it would be ludicrous (and dangerous) to have the Specified properties being set in your UI.

So what's the solution? You'll note, that when a property is set, it calls the "RaisePropertyChanged" method (not included in the above generated code, but it will be there actually), which in turn fires an event. You can subscribe to this event and set your Specified property automatically through Reflection.

Luckily Service Reference classes are defined as Partial, which means you can expand out these classes without tinkering with generated code - this is of critical importance as every time you refresh your reference, the main classes will be wiped out along with any changes you've made.

So I've created a second file elsewhere with my custom code:
public partial class MyObject {
public MyObject() : base() {
this.PropertyChanged += MyObject_PropertyChanged;
private void MyObject_PropertyChanged(object sender, PropertyChangedEventArgs e) {
PropertyInfo prop = this.GetType().GetProperty(e.PropertyName + "Specified");
if(prop != null) prop.SetValue(this, true);

Whenever the data property is set, it's companion Specified property is automatically set. You have to be careful here with default values in .NET, an int for instance will default to 0, so if that is accidentally assigned then it'll get sent over with your message instead of being left out.

Windows 10 - IPv6 resume from sleepTuesday 13th October 2015
I haven't got an answer for this one yet.

It seems when my PC resumes from sleep it (sometimes?) can't connect to IPv6 addresses out on the net. The cause seems to be down to routers and neighbour discovery. This command will list your IPv6 neighbours, and which ones are routers:
netsh interface ipv6 show neighbors
Mine gives me a type of "Stale (Router)" next to my gateway.

It seems, I can kick Windows into life merely by pinging the router address "ping -6 [router]". Repeating the netsh command above will show the router as Reachable, and IPv6 is working.

Doing a trace before the fix, Windows tries to go out directly and is skipping the router at all - naturally, this doesn't work. The ping sorts it out and it starts going out the correct way.

If you happen to know the answer, please let me know!

Dynamics GP 2015 - Econnect web-service SecurityExceptionTuesday 6th October 2015
It seems that the 2015 Dynamics GP (formally, Great Plains) Econnect webservices installer doesn't quite set things up correctly in terms of security permissions.

When an error is triggered via a web-service call (e.g. validation error), you get a rather misleading System.Security.SecurityException wrapped up in your SOAP Fault:
The source was not found, but some or all event logs could not be searched.  To create the source, you need permission to read all event logs to make sure that the new source name is unique.  Inaccessible logs: Security.
This is a fairly common error when dealing with the EventLog. Event Log entries have a source associated with them, in order to create a new source an application required administrative privileges. So, normally, this is something the installer will do as part of setup, as obviously you should not run service-accounts as administrators.

To work past this, I exported the EventLog registry configuration from "HKLM/SYSTEM/CurrentControlSet/Services/EventLog/". I then changed the permissions on this key to grant read/write access to the service account that DynGPWebService account runs under. I re-ran the web-service call that was causing the error and then re-exported the registry key.

I compared the results using a source merge tool and it showed a new entry:

Windows Registry Editor Version 5.00

It's an expanded string, but in plain English, it will display a value of "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll" in regedit.

Reverting the permissions on the EventLog to normal is fine at this stage as the key has been setup.

The alternative approach is to run Process Explorer and monitor what registry keys access is denied for. The snag with this approach is the application will often request access at a higher-level in the tree, so you can't get very granular.

Intel RST RAID-0 recoverySaturday 3rd October 2015
I decided to update my BIOS to see if would resolve a few bugs. To my dismay both of my two RAID0 stripped arrays weren't working.

It's normal for your computer to lose the RAID setting in your BIOS during an update, but setting it back to RAID from AHCI usually is enough for the array configuration to be recognised. For some reason this time it didn't. One disk of each of the arrays were listed as members, the others not.

Fortunately for me, my primary boot drive is a single PCIe SSD, so my OS would still boot fine. Running Intel RST (Rapid Storage Technology) in Windows listed the same error for each array:
Your volume appears inaccessible.  Try fixing any problems reported on the array disks.  If this fails, review the Troubleshooting section under Help for more information.  In all cases, back up any accessible data before taking action.

Unknown disk on Controller 255, Port Unknown: Missing

Of course, being sensible computer users, you'll have a backup of all the data on those drives - but it's always a hassle recovering data, for one, it takes an age when you have large disks.

Fortunately there is a quick fix. It seems this doesn't work for everybody, and it's likely to be entirely down to what caused the error in the first place.

If your data is critical, then use a disk-imaging program to clone all your physical drives at block-level. You then have a backup just in case you muck things up, or it doesn't work for you.

  1. Go into your BIOS and take a note of your array settings (e.g. stripe size)

  2. Delete the array volume, casually dismissing the horrific notice that all data will be lost (it won't, just information about the array is lost, it doesn't actually write to your disk)

  3. Recreate the array volume with the exact same settings, being sure to add the disks back in in the same order as you did originally

  4. Boot into your OS and run TestDisk (if you haven't come across this before, keep a note of it, it's wonderful)
    1. Create a new log file

    2. Identify and proceed with your array volume (not one of the member disks), which will be listed as /dev/sd?? whether you're on Linux or Windows

    3. Select your partition type, which will probably be EFI GPT, or if on an older system, Intel

    4. Select Analyse

    5. Select Quick Search

    6. It's likely it'll sit analysing cylinders - it won't find anything. Select Stop

    7. Select Deeper Search

    8. Hopefully your partitions will appear reasonably quickly in the list - select Stop when they do

    9. Use the up/down arrows to select your partitions.

    10. You can use "p" to view files on that partition; but generally you want to use left/right arrows to select the partition as primary (or whatever status is correct for that partition)

    11. Once all partitions have been configured, press Enter to continue

    12. If you're happy with the structure, select Write

    13. Dismiss and exit the application

  5. You can now reboot your computer and your array should be back to normal as if nothing had happened.

Visual Studio 2015 - Razor IntelliSense not workingThursday 1st October 2015
When editing *.cshtml files in Visual Studio 2015 I do not get any IntelliSense for Razor operators. e.g. If I type @Html. I don't get any hints come up.

In addition, rather suspiciously, when I open a *.cshtml file for the first time I receive the error
An exception has been encountered.  This may be caused by an extension.

You can get more information by examining the file

That ActivityLog file can get pretty big, so if you're going to examine it, it's probably best to delete it first and regenerate the error. In mine there was a fairly obvious error jumping out at me:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'RazorSupportedRuntimeVersion' Key being added: 'RazorSupportedRuntimeVersion'

And so on.

The proposed solution for this around the web is to run "devenv /resetuserdata". This failed immediately for me as for some reason that command tried to launch Visual Studio 2010, which isn't installed. Fortunately, there is a fix for this too. That's a regedit tweak to: "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe". The default value is the path to the current Visual Studio installation, so for me I just needed to replace "10.0" to "14.0" in the file path and the command worked.

Mine still popped up with "Unknown Error" during the reset process, but once I launched Visual Studio (and gone through initial setup again) it all worked as expected.

Previous Next