RSS

WMI Filter for laptops

For filtering laptops in a WMI query there are several different approaches to find out if a system is a laptop or not. A suggested way found on the internet is following WMI query

SELECT * FROM Win32_Battery WHERE (BatteryStatus <> 0)

This works, but if you remove the battery from your laptop and keep the lLaptop on the power chord only this will not work. Then the laptop seems to be a desktop machine. A better approach is to use the following WMI-query:

SELECT * FROM Win32_ComputerSystem WHERE PCSystemType = "2";
 
Leave a comment

Posted by on September 29, 2014 in Windows Server

 

Tags: ,

Inlines and Run in TextBlock does not follow Language override

If you want to localize your application you generally override the LanguageProperty with your desired language:

FrameworkElement.LanguageProperty.OverrideMetadata(
    typeof(FrameworkElement), 
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

As stated in the documentation every control should now use the – in this case – German culture. Well this is not the case. If you have a TextBlock and set the Text property then this works, but if you have a TextBlock with Inline elements, then the en-us culture is used.
This is very stange. Why is that the case? TextBlock inherits from FrameworkElement and because you have overridden the FrameworkElement.LanguageProperty this works. But if you use Inlines, such as Run, Italic, Underline, … those controls inherits from FrameworkContentElement and not from FrameworkElement for which you do not have overridden the corresponding DependencyProperty. This is the only reason why Inlines do not follow the application wide culture. As solution for that you have to override the LanguageProperty for FrameworkContentElements.

FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(FrameworkElement),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")))

This does not work because it says that is is already registered. So a workaround is to override if for every class that is one inheritance hierarchy lower than FrameworkContentElement:

 FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(DefinitionBase),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

            FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(FixedDocument),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

            FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(FixedDocumentSequence),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

            FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(FlowDocument),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

            FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(TableColumn),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

            FrameworkContentElement.LanguageProperty.OverrideMetadata(
    typeof(TextElement),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));

Now the Inlines in TextBlock follows the culture that you have specified

 
Leave a comment

Posted by on September 25, 2014 in C-Sharp

 

Tags:

Done Building Project “X” (default targets) — FAILED.

If you use Team Foundation Server as build server and have a Database Project that is build on the server there is a chance that the build output succeeds without errors but the build result is “failed”. If you execute msbuild on the build server you can see that the DatabaseProject build succeeds with following output:

Done Building Project “X” (default targets) — FAILED.

Based on the documentation of the TFS-Build-Server any build output containing ERROR, FAILED,… is interpreted as a failed build, even though the msbuild script succeeded.
The problem is that you have not updated the SQL Server Data Tools. If you install the update on your build machine then the MsBuild-Script will succeed

 
Leave a comment

Posted by on September 19, 2014 in Team Foundation Server

 

Tags:

TFS does immediately not see group member changes.

When adding a user to a windows/domain group (e.g. TFS-Users) that has access to a repository on Team Foundation Server it may be that this user does not get immediate access to your Team Collection. This is because Team Foundation Server caches the user that are present in the group TFS-Users. Therefore any user change on the windows/domain group, either removal or addition, will not be reflected immediately to the Team Foundation Service. The solution is to wait some amount of time, since Team Foundation Service will re-query the windows/domain user group for eligible users every hour.

Note: It does not work to shut down the IIS-Webpage and restart it, this will not force a re-query of the windows/domain group.

 
Leave a comment

Posted by on September 11, 2014 in Team Foundation Server

 

Tags:

The located assembly’s manifest definition does not match the assembly reference


“System.IO.FileLoadException: Could not load file or assembly \”System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\” or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”:”System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

Looking in my solution explorer I can see I have referenced System.Windows.Interactivity, Version=4.5.0.0

Windows.Interactivity

But why does he complaint that version 4.0.0.0 is not found. The short answer for the problem is that another referenced library references itself System.Windows.Interactivity with version 4.0.0.0. Therefore, because version 4.5.0.0 is loaded by the version 4.0.0.0 is not found.

The solution is to configure a assemblyBinding in app.config.

This is done as follows:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="System.Windows.Interactivity" 
                          publicKeyToken="31bf3856ad364e35" 
                          culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" 
                         newVersion="4.5.0.0" />
    </dependentAssembly>
</assemblyBinding>
 
1 Comment

Posted by on February 20, 2014 in C-Sharp

 

sql71502 when using INSERTED keyword

Recently I had a strange exception when using the INSERTED keyword. It always mentioned that the Id property does not exists on table X.

SQL71502-Exception

The solution is rather simple. Just put the scheme name to your table then the exception is gone.

SQL71502-Solution

 
Leave a comment

Posted by on January 20, 2014 in SQL

 

Constant Enum: Circular definition

If you have declared an enum field as constant you may get following exception:

The evaluation of the constant value for … involves a circular definition.

The code where this exception appears looks like:

private const Parity Parity = Parity.None;

Well, thats strange. There is no error. I declare a constant field with the same name as the name of the type. This is allowed, because I can also write following line of code, and this would compile

private const String String = "HELLO"

The problem with enums is that the compiler interprets the third Parity not as the name of the enumeration but as the name of the field. Hence, we have a circular reference because the constant is defined by the constant itself. To solve the compile error you have two options: either you add the fully qualified name to the third Parity value or you change the name of the field.

private const Parity Parity = System.IO.Ports.Parity.None;
//or
private const Parity ParityValue = Parity.None;

If you use tools like ReSharper that cleans up the redundant qualifiers than I would suggest you to use the second option.

 
Leave a comment

Posted by on April 29, 2013 in C-Sharp

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.