Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process.GetCurrentProcess().ProcessName is throwing InvalidOperationException for Blazor Webassembly project #56532

Closed
sonupmandal opened this issue Jul 29, 2021 · 6 comments
Labels

Comments

@sonupmandal
Copy link

I have created a simple Blazor Webassembly application in which
Target Framework : .NET Standard 2.1

Contents of Counter.razor file

@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        var CurrentProcess = System.Diagnostics.Process.GetCurrentProcess();
        var pname = CurrentProcess.ProcessName;

        currentCount++;
    }
}

Upon running this application, a browser window opens, when i press click me button, i end up getting this exception.
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Process has exited or is inaccessible, so the requested information is not available.
System.InvalidOperationException: Process has exited or is inaccessible, so the requested information is not available.
at System.Diagnostics.Process.get_ProcessName () <0x2d34700 + 0x0004a> in :0
at WebApplication1.Pages.Counter.IncrementCount () <0x2d33d80 + 0x0000c> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T] (System.MulticastDelegate delegate, T arg) <0x2d07e80 + 0x0005e> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync (System.Object arg) <0x2d07bc0 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync (Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, System.Object arg) <0x2d07b28 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync (System.Object arg) <0x2d076f0 + 0x00040> in :0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync (System.UInt64 eventHandlerId, Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo fieldInfo, System.EventArgs eventArgs) <0x2d06ce0 + 0x000a8> in :0

Can someone assist me why i am getting this error ? Is Process.GetCurrentProcess().ProcessName API not supported with Blazor webassembly app ?

@sonupmandal
Copy link
Author

my simple blazor app repo link : https://github.com/sonupmandal/WebApplication.git

@davidfowl
Copy link
Member

What would you expect the process name to return when running in the browser sandbox?

@En3Tho
Copy link
Contributor

En3Tho commented Jul 29, 2021

There is an answer from @danroth27 in your previous issue that explains the exception.

@javiercn javiercn transferred this issue from dotnet/aspnetcore Jul 29, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Diagnostics.Process untriaged New issue has not been triaged by the area owner labels Jul 29, 2021
@ghost
Copy link

ghost commented Jul 29, 2021

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

I have created a simple Blazor Webassembly application in which
Target Framework : .NET Standard 2.1

Contents of Counter.razor file

@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        var CurrentProcess = System.Diagnostics.Process.GetCurrentProcess();
        var pname = CurrentProcess.ProcessName;

        currentCount++;
    }
}

Upon running this application, a browser window opens, when i press click me button, i end up getting this exception.
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Process has exited or is inaccessible, so the requested information is not available.
System.InvalidOperationException: Process has exited or is inaccessible, so the requested information is not available.
at System.Diagnostics.Process.get_ProcessName () <0x2d34700 + 0x0004a> in :0
at WebApplication1.Pages.Counter.IncrementCount () <0x2d33d80 + 0x0000c> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T] (System.MulticastDelegate delegate, T arg) <0x2d07e80 + 0x0005e> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync (System.Object arg) <0x2d07bc0 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync (Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, System.Object arg) <0x2d07b28 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync (System.Object arg) <0x2d076f0 + 0x00040> in :0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync (System.UInt64 eventHandlerId, Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo fieldInfo, System.EventArgs eventArgs) <0x2d06ce0 + 0x000a8> in :0

Can someone assist me why i am getting this error ? Is Process.GetCurrentProcess().ProcessName API not supported with Blazor webassembly app ?

Author: sonupmandal
Assignees: -
Labels:

area-System.Diagnostics.Process, untriaged

Milestone: -

@danmoseley danmoseley added the arch-wasm WebAssembly architecture label Jul 29, 2021
@ghost
Copy link

ghost commented Jul 29, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

I have created a simple Blazor Webassembly application in which
Target Framework : .NET Standard 2.1

Contents of Counter.razor file

@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        var CurrentProcess = System.Diagnostics.Process.GetCurrentProcess();
        var pname = CurrentProcess.ProcessName;

        currentCount++;
    }
}

Upon running this application, a browser window opens, when i press click me button, i end up getting this exception.
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Process has exited or is inaccessible, so the requested information is not available.
System.InvalidOperationException: Process has exited or is inaccessible, so the requested information is not available.
at System.Diagnostics.Process.get_ProcessName () <0x2d34700 + 0x0004a> in :0
at WebApplication1.Pages.Counter.IncrementCount () <0x2d33d80 + 0x0000c> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T] (System.MulticastDelegate delegate, T arg) <0x2d07e80 + 0x0005e> in :0
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync (System.Object arg) <0x2d07bc0 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync (Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, System.Object arg) <0x2d07b28 + 0x0000a> in :0
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync (System.Object arg) <0x2d076f0 + 0x00040> in :0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync (System.UInt64 eventHandlerId, Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo fieldInfo, System.EventArgs eventArgs) <0x2d06ce0 + 0x000a8> in :0

Can someone assist me why i am getting this error ? Is Process.GetCurrentProcess().ProcessName API not supported with Blazor webassembly app ?

Author: sonupmandal
Assignees: -
Labels:

arch-wasm, area-System.Diagnostics.Process, untriaged

Milestone: -

@adamsitnik
Copy link
Member

Can someone assist me why i am getting this error ? Is Process.GetCurrentProcess().ProcessName API not supported with Blazor webassembly app ?

Entire System.Diagnostics.Process is not supported for WASM (#41694). We have introduced new analysers that produce warnings at compile time (.NET 6) in order to avoid such situations.

@adamsitnik adamsitnik removed the untriaged New issue has not been triaged by the area owner label Jul 30, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants