Can't seem to enable\disable feature without exception

Mar 16, 2014 at 1:37 PM
Hi,

I'm trying to enable\disable windows components (Specifically TelnetServer) using your Wrapper.
I'm constantly getting exceptions.
This is my sample code:
using System;
using Microsoft.Dism;


namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);
            DismSession openOnlineSession = DismApi.OpenOnlineSession();
            DismApi.EnableFeatureByPackageName(openOnlineSession, "TelnetServer", null, true, false);
            openOnlineSession.Close();
            DismApi.Shutdown();

        }
    }
}
When trying to run it like that, the feature is indeed enabled but results in a null reference exception (Returned from calling NativeMethods.DismEnableFeature - which results in error code 1).

Also, when trying to set a log file using:
DismApi.Initialize(DismLogLevel.LogErrors, @"c:\");
I get a COMException.

My dll files are located in the project base folder.

I'd really appreciate your help
Coordinator
Mar 17, 2014 at 3:23 PM
I just fixed a bug last week related to this. Make sure you have the latest release.

Please check the documentation on DismInitialize. It looks like the log file path needs to a file not a directory.
Optional. A relative or absolute path to a log file. All messages generated will be logged to this path. If NULL, the default log path, %windir%\Logs\DISM\dism.log, will be used.
If you still have issues, let me know and I'll see what I can do!
Mar 18, 2014 at 2:22 PM
Hi,

Thanks for the reply. I indeed checked and have the latest binaries. The funny thing is I'm running into this issue only on Win7. If I run my code on Win8 it runs smoothly.
The Thing is, when the native method DismEnableFeature is invoked, it results in error code 1 - When you try to call GetDismExceptionForHR(1) it results in null being throws (since it can't seem to translate 1 to a proper error).

You did a great job on the wrapper and I can deal with the bug by catching a null reference exception but I would love it if you could look into why I'm getting this error.

Thanks in advance
Coordinator
Mar 18, 2014 at 10:41 PM
Okay I'll see if I can figure out what is going on and will get back to you.