views:

115

answers:

1

I have an assembly written in C++/CLI that contains a heap of enum defined like the following, one after the other in a single header file.

namespace Fix
{

public enum class Side
{
    SideBuy = '1',
    SideSell = '2'
};

}

I can reference these types in other C# projects, and in IronPython, I can reflect the assembly and see them all with no trouble at all. I've also been using them in Powershell for many months with no issues - until now. I reference them like this:

[Fix.Side]::SideBuy

I have just moved from Visual Studio 2008 to Visual Studio 2010 and now some of the enums I have defined like this are invisible to Powershell. I don't see any difference in the declarations and I can reflect the types with no problem.

This is a .NET 4.0 assembly and I have configured Powershell to run with the 4.0 runtime. I did that with the following registry changes.

reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1

Has anyone had issues like this?

+2  A: 

It works for me. My steps:

I build a C++/CLI .NET 4.0 assembly with a single source file (except stdafx.*):

#include "stdafx.h"

namespace Fix 
{ 
    public enum class Side 
    { 
        SideBuy = '1', 
        SideSell = '2' 
    }; 
} 

Then I create and invoke this test script:

Add-Type -Path "C:\...\TryEnum40.dll"
[Fix.Side]::SideBuy

It works: the enum value is printed as expected.

How do I configure my PowerShell to work with .NET 4.0? I do not use any registry tricks. I create the XML file “powershell.exe.config” in the PS home directory (or in a home directory of an application that implements a PowerShell host (e.g. MyApp.exe.config), I tried such a scenario, too).

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0.30319"/>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

x64 machine: the file also needs to be copied to C:\Windows\SysWOW64\WindowsPowerShell\v1.0

P.S. If this still does not help, could you please provide the exact error message that you get?

Roman Kuzmin
No joy, thanks for the config file option though, the registry hack was a pain because it affected other software.
Gary
The simple case you've demonstrated also works for me, in the real situation I have many enums defined in the header file. Powershell simply says it cannot find the type, I can also get it to fail on different types by reordering the declarations. It's very strange. I've also had a user report the same problem with a class type.
Gary