Showing posts with label MSFT utilities. Show all posts
Showing posts with label MSFT utilities. Show all posts

Thursday, January 10, 2019

Yet another MSBuild-on-Linux back-slash gotcha

Another variant of a known family of such issues, encountered as AltCover issue #49, the interesting tale of what you get when your MSBuild sets a task array parameter with

AssemblyExcludeFilter="$(AltCoverAssemblyExcludeFilter.Split('|'))"

and the value of AltCoverAssemblyExcludeFilter is the-|xunit\.; surprisingly, the answer is

the-
xunit/.

There isn't even an explicit ItemList in sight, and yet the '\' still gets interpreted as a path separator and "helpfully" *nix-ified. Doubling up the '\' via .Replace('\','\\') ahead of the split doesn't escape the character -- you just get a '//' in the output, nor does escaping on the command line as the-|xunit%5C..

For the moment, with no obvious MSBuild level fix, I'm working around this by doing .Replace('\', %00) and then converting the NUL back inside the custom MSBuild task.


Sunday, November 27, 2016

Fixing SMB access in recent Windows 10 updates

One of the updates that came down the wire to the machine I'm running on the insider slow ring in the last few weeks had the effect that trying to access the SMB share on my router gave a message like

\\Remote-Server\Path is not accessible. You might not have permission to use this network resource. Contact the administrator of this server to find out if you have access permissions. etc.

Breaking out Wireshark and comparing a machine still on build 1607 (local account login) with the test machine (MSFT login) showed that the SMB handshake would perform the initial exchange of Session Setup AndX Request, NTLMSSP_NEGOTIATE and Session Setup AndX Response, NTLMSSP_CHALLENGE, Error: STATUS_MORE_PROCESSING_REQUIRED, but the test machine would not then emit a Session Setup AndX Request, NTLMSSP_AUTH, User: Machine\User packet. Further experiment would be needed to tell whether this is because I'm running that machine with a MSFT login rather than a local account, rather than it being an insider build, but in the end, the fix turned out to be going to Control Panel\User Accounts\Credential Manager and creating a new Windows credential just for the Remote-Server address, with username and password sufficient to log on to the share (so for a wide-open read-only share, any username and an empty password will do).

Tuesday, December 27, 2011

Writing StyleCop rules in F#

Alas not "Writing StyleCop rules for F#" (or should that be StyleFop?), which would be nice, but a true job of work...

I don't see much need for more StyleCop rules for C# (except one to harness the FxCop spellcheck facilities to scan comments, which would have to be done via much dodgy reflection to winkle out internal types, and would anyway give issues for being tied to 32-bit native executables), so haven't tried this before. But, like mountains, it's there...


So, you have StyleCop 4.5 or 4.6 installed, and start by creating an empty class library targeted at the .net 3.5 environment, with added references to the StyleCop and StyleCop.CSharp assemblies. The bare rule class looks like

and to go with it, add an XML file as an Embedded Resource with name My.Namespace.MyRules.xml -- first gotcha : the long name needs to be given in full because the default namespace doesn't get applied in the build like it would for C#. That can then be filled in as per the instructions in the StyleCop SDK documentation. Then just override the AnalyzeDocument method and go wild:

where I'm using the concept from the StyleCop+ rule SP2000 as an example of a new rule not yet present in the core tool.

Unlike FxCop, there is not a "one class = one rule" model here; the classes exist to group related rules, and you control how each scans the current source file of interest, and, indeed, how distinct they are in the code -- a closely related set of rules could be checked off a single scan, and in some ways StyleCop rules are more akin to the distinct named resolutions that can be defined within a single FxCop rule.

Another consequent difference from FxCop is how the object graph is visited. In FxCop, there are VisitXxx methods to override that will be called for every object of type Xxx, in an essentially stateless manner (your rule class is responsible for maintaining state between calls); here the equivalent methods are passed to a WalkXxx graph walker method as a callback, provide a mutable state object argument, and can signal through their return value whether the traversal should continue.

This approach of using a mutable object, needing down-casting, to carry inputs into each call, and contain the resultant outputs, feels a bit odd in a functional environment; fortunately it is possible to bypass this in many cases by representing the tree-walk as a seq and operating on that. For the trailing whitespace rule, where the offending lines are most easily found by scanning the raw source line by line, all we need the traversal for is to find an ICodeElement context object matching that line number. A simple walk of the code element tree looks like

which we apply to the document RootElement and from the result find the last (so most deeply nested, and hence most constrained) item whose Location has a span that includes the line number of interest (skip while the end is before the line of interest, take while the start includes the line, reverse, get head), the line number being a value that the operation can close over.

For deployment onto machines that don't have F# installed, static linkage of the runtime via the --standalone build flag can be used rather than having to explicitly drop the F# runtime assembly into the StyleCop folder (second gotcha).

Saturday, April 09, 2011

More than you wanted to know about sc.exe and service isolation in Windows 2k3 SP2

At the level of Win2k3 SP2 unpatched, sc.exe did not support the sidtype parameter for setting a per-service SID. If you issue

sc.exe sidtype MyService Unrestricted

it spits out help text, then pauses for user input

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:

At patch MS09-012/KB959454 (or maybe KB956572), if not before, sc.exe was upgraded to interpret this parameter. However...

If on 64-bit Win 2k3 with that patch, you run the 32-bit -- Program Files (x86) -- version, that will accept the sidtype parameter and do nothing, at least on the various systems I've tested on.

Tuesday, January 11, 2011

Using F# 2.0 Powerpack ArgParser from C# -- (ii)

Having resolved the issue of why the "--" separator wasn't triggering (PowerShell was swallowing it before it got to my code) that was stumping me in the previous post, I put together a little fluent wrapper to make this a little easier to consume from C#. The code that isolates the F# types looks like this:

The calling code, for the same example as before looks like

which is much clearer.

Now edited for FxCop.

Monday, January 10, 2011

Using F# 2.0 Powerpack ArgParser from C#

This is an update of the technique mentioned in an antique post by Robert Pickering which was referenced by Laurent Le Brun last summer. I've taken Laurent's example of F# usage and ported it to C# in the most direct fashion:

It is possible to streamline this to hide most of the messy type names inside utilities.

One thing I've not managed to do is get the lambda associated with the ArgType.Rest to fire, even after setting the default handler opt1 to FSharpOption<T>.None. That -- the default handler -- gets fired every time an otherwise unmatched argument is encountered; the ArgType.Rest handler looks from the code like it should "just work" so I'm a bit baffled ATM.

LATER: Mystery solved

Of course, I was testing this at a PowerShell prompt -- and the shell was swallowing the unquoted "--" string : there was no "rest" to operate on.

Monday, December 14, 2009

Using a different mscorlib for F# in Visual Studio (Silverlight and probably XNA too)

It turns out that I was lucky last year when building an F# Silverlight 2 application by hand in Visual Studio -- I didn't make an explicit reference to mscorlib.

If you explicitly browse to the Silverlight mscorlib assembly to make an explicit reference, the .fsproj file still only gets the basic

    <Reference Include="mscorlib"/>

which falls back to the full framework version of the assembly when you compile. This behaviour has caused some people to abandon the exercise of getting F# to build against something non-default in Visual Studio.

However, the way forward is very simple indeed -- simply edit the .fsproj to give an explicit hint path pointing at the mscorlib you really mean:

    <Reference Include="mscorlib">
      <HintPath>C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v3.0\mscorlib.dll</HintPath>
    </Reference>

and get the confirmation that this sticks in the command line that echoes to the Output window

C:\Program Files\FSharp-1.9.7.8\\bin\fsc.exe -o:obj\Debug\Library3.dll -g --debug:full --noframework --define:DEBUG --define:TRACE --optimize- --tailcalls- -r:"C:\Program Files\FSharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll" -r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v3.0\mscorlib.dll" --target:library --warn:3 --warnaserror:76 --vserrors --utf8output --fullpaths --flaterrors Module1.fs

Problem sorted.

(Generalise as required to any other assemblies which refuse to stay pointed at the platform you want.)

Save the version number in the output, this advice is unchanged by the February 2010 CTP.

Friday, July 31, 2009

T4 Gotcha -- fun with text transformations

A colleague of mine was having trouble with some T4 templating, which was giving apparently insane results. Figuring it out and thus fixing it took me rather longer than it ought to have, so just in case anyone else runs into the same problem...

Have some T4 template code that looks like -- after adding all the debug tracing to try and find out what was going wrong:

where obj is defined elsewhere; and you can get results like

Doing property for Address
obj.Property is not null
obj.Property is null
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TextTemplating32fcf58db1db4a9da645eda11cd4add4.GeneratedTextTransformation.TransformText()

which appear to defy sanity.

What is actually going on is that the intermediate code generated by the TextTransform program looks like

where the leading whitespace in "            <#     { #>" is being processed in such a way as to consume the if statement.

So, despite the official MSFT brace style being Allman, T4 is actually one of those places where the K&R style is going to be much safer.

Or if that is too heretical a notion, then keep the "<#" at the start of lines except where you explicitly want the whitespace or simply do not bracket on a per-line granularity (with the same proviso) --

will help preserve your sanity.

Wednesday, July 15, 2009

MMC 3.0 managed snap-ins on WinXP

The problem:

I needed to do some stuff with snap-ins and I didn't want to take the hit of building a new dev box -- but on my XP box I was getting:

>InstallUtil  .\ManagedSnapIn.dll
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053
Copyright (c) Microsoft Corporation.  All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly's progress.
The file is located at C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.InstallLog.

Installing assembly 'C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll
   logfile = C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.InstallLog
An exception occurred while trying to find the installers in the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Aborting installation for C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll.

An exception occurred during the Install phase.
System.InvalidOperationException: Unable to get installer types in the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to
 load one or more of the requested types. Retrieve the LoaderExceptions property for more information..

The solution:

As noted here, the mmcperf tool registers 3 MMC assemblies to the GAC for you

>mmcperf.exe
Successfully installed assembly C:\WINDOWS\system32\MMCEx.dll to the Global Assembly Cache (GAC).
Successfully installed assembly C:\WINDOWS\system32\MMCEx.dll to the Native Images Cache.
Successfully installed assembly C:\WINDOWS\system32\MMCFxCommon.dll to the Global Assembly Cache (GAC).
Successfully installed assembly C:\WINDOWS\system32\MMCFxCommon.dll to the Native Images Cache.
Successfully installed assembly C:\WINDOWS\system32\Microsoft.ManagementConsole.dll to the Global Assembly Cache
Successfully installed assembly C:\WINDOWS\system32\Microsoft.ManagementConsole.dll to the Native Images Cache.

which let the InstallUtil run successfully -- but you could probably get away with just copying them into the folder with the snap-in (you need the last as an explicit reference anyway).

Thursday, April 16, 2009

windows "internet time" "RPC server is unavailable"

Finally (after all these years) I got annoyed enough to track down why Internet Time wasn't working on all of my XP or Vista boxes.

Despite the Internet Time synch tab being there out of the box on the system clock, there is a manual step needed to enable it. The Windows Time service needed to back it up isn't registered by default (check the Administrative Tools service applet). So, at a DOS prompt, enter

w32tm /register

Then in the Administrative Tools service applet manually start the Windows Time service.

Then and only then will the Update Now button work.


Addendum 12-Mar-12

Searching for other mentions of the service registration, there appear to be some problem reports where the service is registered, but the time synch still fails. This is not a problem I personally have ever seen, but in those articles, the fix reported in these cases is

w32tm /unregister
w32tm /unregister
w32tm /register

where you have to ignore the errors from both the first two commands to de-register the service.