Jay
Jay

Reputation: 2129

Powershell reflection load running dll

For debugging, I need to read a static property from a c# class while it is being used by a web application. For various reasons I am not able to run a debugger on this environment.

Using reflection in a .aspx file, I am able to extract the value I need, however I would like to accomplish this with powershell.

Is this possible?

As a rough example, I have the following class

public static class MyClass{

    public static string TheData{
        get{return _dataValue};
    }
}

I need to read the value of 'TheData', which only exists when the application is running.

Upvotes: 0

Views: 256

Answers (1)

CodeCaster
CodeCaster

Reputation: 151584

You can't do this by directly inspecting the class from another process. A static class lives once inside an AppDomain, which is restricted to its own process. Running PowerShell is a different process, so it has its own AppDomain, having its own version of the static class.

If you see Accessing static members across processes C# and Get AppDomain for another .NET framework process, you'll see "Inter-Process Communication" or IPC is recommended. You'll have to create an entry point in your web application where you can read this information from the process.

You can also simply create an ASPX page that exposes the variable, and do an HTTP request to that page from PowerShell using Invoke-WebRequest.

Upvotes: 1

Related Questions