The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘.NET’ Category

Some PowerShell SCCM links

Posted by jpluimers on 2012/03/22

http://www.powershell.nu/2010/10/07/powershell-sccm-client/

http://www.powershell.nu/tag/sccm-2007/

 

http://devinfra-us.blogspot.com/2008/04/sccm-and-powershell-part-1.html

http://devinfra-us.blogspot.com/2008/04/sccm-and-powershell-part-2.html

 

http://thepowershellguy.com/blogs/posh/archive/2008/05/16/sccm-and-powershell-series-using-my-powershell-wmi-explorer.aspx

http://thepowershellguy.com/blogs/posh/archive/tags/WMI+Explorer/default.aspx

http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx

 

http://tfl09.blogspot.com/2010/03/sccm-powershell-module.html

 

http://www.snowland.se/2010/03/10/sccm-module-for-powershell/

http://www.snowland.se/sccm-posh/

 

Posted in .NET, PowerShell, Scripting, Software Development | Leave a Comment »

Enabling powershell to run unsigned scripts for the current user only (via: Absoblogginlutely!)

Posted by jpluimers on 2012/03/21

More than a year ago, I wrote about enabling PowerShell to run unsigned scripts, and a way to circumvent the “cannot be loaded because the execution of scripts is disabled on this system” error.

The solution  there uses the Set-ExecutionPolicy cmdlet, but only works for administrators. As of PowerShell 2.0, there is more fine grained control for the Set-ExecutionPolicy cmdlet, and an updated Set-ExecutionPolicy cmdlet topic which I overlooked.

The solution below shows what happens when the current user is not an administrator, and works around it by applying it only for the current user.

error message:

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.

Sure enough I don’t have permission to this registry key.

I checked with our admin to ensure this wasn’t set in group policy before I started fiddling around. Found out that there is another setting that is user specific that can be set with

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

This will allow the current user to run unsigned scripts he wrote himself, but still require remote (for instance downloaded) scripts to be signed.

Note it is easy to strip the “remote” flag of a downloaded script: NTFS keeps this flag in the Zone:Identifier NTFS alternate data stream.
Only do that for scripts you trust.

–jeroen

via: Absoblogginlutely! » Enabling powershell to run scripts with registry permissions..

Posted in .NET, Development, PowerShell, Scripting, Software Development | 4 Comments »

.NET/C#: Resolved errors “The type ‘NameSpace.TypeNameClass’ has no constructors defined” and “Interop type ‘NameSpace.TypeNameClass’ cannot be embedded. Use the applicable interface instead.” (via Stack Overflow: Interop type cannot be embedded)

Posted by jpluimers on 2012/03/20

When moving the Microsoft Scripting Runtime interop code from .NET 1.x to 4.x, I got these errors:

Error1: The type 'Scripting.FileSystemObjectClass' has no constructors defined
Error21: Interop type 'Scripting.FileSystemObjectClass' cannot be embedded. Use the applicable interface instead.

Though the first answers on the question seem to adequately resolve the problem, they merely cure the symptom: turning off the embedding of the PIA (Primary Interop Assembly).

The below answer by Michael Gustus (which only has a few votes, so please vote it up) actually explains what is going on, and solves the cause:

In most cases this error is the result of code which tries to instantiate a COM object e.g. here piece of code starting up Excel:

Excel.ApplicationClass xlapp = new Excel.ApplicationClass();

Typically, in .Net 4 you just need to remove the ‘Class’ suffix and compile the code:

Excel.Application xlapp = new Excel.Application();

MSDN explanation here.

Hence I like the comment by Tyrsius on this answer as well:

This was more useful than the marked answer, as I needed the functionality of the embedded Interop. This solved both problems, thank you!

The above answer tells you to not use the class type, but the interface type, just like the error states. And the answer implicitly tells you the class type is ApplicatoinClass, and the interface is Application.

These are the declarations for the PIA interface: Read the rest of this entry »

Posted in .NET, C#, C# 4.0, Development, Software Development | Leave a Comment »

A few reminders to self for AMP in VS11: debugging, writing, etc

Posted by jpluimers on 2012/03/15

Reminders to self:

–jeroen

via: The Moth – GPU Debugging with VS 11.

Posted in .NET, C#, Development, Software Development, Visual Studio 11, Visual Studio and tools | Leave a Comment »

WTF C# code of the month

Posted by jpluimers on 2012/03/14

When I come across code like this, I’m always astonished:

			catch(Exception ex)
			{
				string strMess = ex.Message;
			}

What was the person thinking when he wrote this? Did he get distracted and nobody else notice this before checking it into their version control system?

In the same module:

		private string ToString(object myVal)
		{
			try
			{
				if (myVal != System.DBNull.Value)
					return myVal.ToString().Trim();
			}
			catch{}

			return "";
		}

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Solution for TFS2005/2010 and VS2005/2010: Add/New Work Item menu still loading (try again in a moment)…

Posted by jpluimers on 2012/03/13

Sometimes when creating new Team work items in Visual Studio 2010 connected to Team Foundation System 2010, you get a sub menu like this:

New Work Item menu still loading... (try again in a moment)

“New Work Item menu still loading… (try again in a moment)”

There are not many results in the new work item menu still loading “try again in a moment” site:microsoft.com query, but luckily the first one shows a similar issue in Visual Studio 2005 with Team Foundation System 2005: the “Add Work Item menu still loading… (try again in a moment)”.

The solution is also very simple:

  1. Quit Visual Studio 2010
  2. Delete this registry key
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\WorkItemTracking\TeamMenu\AddWorkItemMru
  3. Start Visual Studio 2010
  4. Retry (can take more than a minute, but it usually works)
The only difference between the Visual Studio 2010 (version 10.0) and Visual Studio 2005 (version 8.0) is the version number:
  • HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\WorkItemTracking\TeamMenu\AddWorkItemMru

Not sure if this can fail in Visual Studio 2008 too, but if it does, just apply this fix with version number to 9.0, and if it happens with the Visual Studio 11 developer preview, change the version number to 11.0.

–jeroen

via: Add Work Item menu still loading….

Posted in .NET, Development, Software Development, Visual Studio 2005, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

How to install Windows 7 on a virtual hard disk (VHD) in 10 steps (via: Guides & Tutorials)

Posted by jpluimers on 2012/03/12

Handy when working with Microsoft Surface: install your development environment on a separate VHD that you can boot as your physical machine (Microsoft Surface SDK does not like being run in a Virtual Machine):

If you accept the constraints described above, I propose the following procedure, which I think is the easiest way to install Windows 7 on a virtual disk in multi-boot

Note: Within the VHD you can still access all the files on your physical HD.

–jeroen

via: How to install Windows 7 on a virtual hard disk (VHD) in 10 steps – Guides & Tutorials.

Posted in .NET, C#, Development, Microsoft Surface, Microsoft Surface on Windows 7, Power User, Software Development, Windows, Windows 7, WPF, XNA | 1 Comment »

“Cannot navigate to definition” annoyance in Visual Studio 2010 – (did it implement the mouse equivalent to Delphi code browsing? No, it didn’t)

Posted by jpluimers on 2012/03/08

This use case drove me nuts in Visual Studio 2010 for a while, but can be solved.

Use cases:

  1. Cannot navigate to definition.double click on a word to select it
  2. press Ctrl-C to copy the selected text
  3. result is either of these two dialogs:

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    Cannot navigate to definition.
    ---------------------------
    OK
    ---------------------------

    Cannot navigate to definition. The cursor is not on a symbol.or

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    Cannot navigate to definition. The cursor is not on a symbol.
    ---------------------------
    OK
    ---------------------------

The reason is that Visual Studio 2010 still thinks I am clicking the identifier (which I’m not, I just released the mouse button) while pressing the Ctrl key. Read the rest of this entry »

Posted in .NET, Delphi, Development, Keyboards and Keyboard Shortcuts, Power User, Software Development, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

Eric Lippert’s comment and answer explaining nullable operator lifting (c# – Why does the == operator work for Nullable when == is not defined? – Stack Overflow)

Posted by jpluimers on 2012/03/07

It seems I’m not the ony one who watches what Eric Lippert writes closely.

Eric works at the C# team at Microsoft (since 1996, which is about the time Anders Hejlsberg joined Microsoft).

Unlike Anders, Eric is much more visible. I regularly read his blog, and watch his StackOverflow.com contributions (RSS feed) on a regular base.

Recently, he posted a awesome comment “Nullable is nothing but magic” on a the question “C# – Why does the == operator work for Nullable when == is not defined?“, together with a very concise answer explaining that in C# most operators are ‘lifted to nullable’.

Note his tiny – but important – mention that for == VB.net behaves different than C#.

Note that Eric is very productive, he usually contributes to StackOverflow.com multiple times a day, sometimes with material that (at least for me <g>) need a while before I really get the point.

Recommended reading :)

–jeroen

via: c# – Why does the == operator work for Nullable when == is not defined? – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET | Leave a Comment »

Anyone with a C#, Delphi or FreePascal implementation of the PRESENT Ultra-Lightweight Block Cipher encryption?

Posted by jpluimers on 2012/03/06

A short while ago a paper got published on PRESENT: An Ultra-Lightweight Block Cipher by Andrey Bogdanov et al becoming ISO standard 29192-2:2012.

Is there anyone that has a C#, Delphi or FreePascal implementation with unit tests?

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Development, Software Development | 13 Comments »