I created a desktop app that control usb device now i want to convert the app to a webapp but the problem is the ASP.net core doesn't detect the usb device i tried many solutions but the same result the usb device and website are all in my pc i tried other
technologies like node js and python django it worked fine on those but i want to do it in asp.net core any other solutions thanks in advance
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Thank you for your answer but i have the functions that can detect usb device it works well in the desktop app but when i try to run it in asp.net web app it doesn't work i tried using node js and it worked well but i want to use asp.net core
it works well in the desktop app but when i try to run it in asp.net web app it doesn't work i tried using node js and it worked well but i want to use asp.net core
It seems you want to make your previous code work in a new asp.net core project?If so,you need to share a sample.
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
its not a sample code its a DLL that have functions that access usb device i just want to map it to asp.net web app and make it work when i run those functions on asp.net they don't work i managed to work the DLL in node js but i want to make it work on
asp.net core web app
Always tell what actually happens rather than just that "it doesn't work". My guess is that this is server side code and so it tries to use a USB device that would be plugged
on the server side (even if it may appear to work on your development machine).
What happens is the DLL have a function that returns the number of usb device connect to the PC it works fine in desktop app but when i run this function in asp.net app it returns 0 devices detected and its not a serverside code actually all things exist
in my PC the web app and usb device so why asp.net web app cannot detect the usb device i gave all the permissions to the web app to access my devices.
It really does nothing else than enumerating devices? If a 3rd party API what if you try their support site. I can only guess that there is an underlying error which is ignored rather than really not finding any device? The
final goal is still unclear.
If you want to show in a browser images taken by a remote camera attached to a web server, AFAIK
https://en.wikipedia.org/wiki/IP_camera are mots often used.
If you want to capture a video from a browser, you have browser side APIs to do this kind of capture.
DLLs run on a web server not the client machine. The camera must be attached to the server's USB port.
Your USB camera might come with software installed on the client the allows streaming video. You'll need to read the documentation for the USB camera you are using or contact support for the camera to make sure the camera will work as expected. You'll certainly
need to configure your network to allow a web server or other internet connected devices to see the camera images by connection to your machine. Your machine becomes a web server.
yeah i am able to call it from c# desktop app and the functions work properly but from asp.net core i can call the functions and the functions work but they cannot detect the usb camera thats the problem.
You are 100% sure it doesn't return some error code you could check? What if you show the
minimal amount of code showing that the camera is not detected? And so I would try on my own to see if it seems an ASP.NET Core side issue or rather a problem in this 3rd party DLL.
I'm still not sure what you'll do with a camera directly attached to a web server rather than to a browser side computer. You want to monitor the web server surrounding ?
If the web site will always run on the same computer to which a camera is attached it could be better to just keep your current desktop app rather than having to install a web server on each and every machine to do the same thing.
I am sure that there is no errors it only doesn't detect usb camera the functions work properly but the problem is the detection of the usb camera there is no problem with the DLL and i don't have the source code of the DLL to show it and the code is simple
i just use p/invoke to call the DLL and use its functions it works well in desktop apps but not in asp.net core or any asp.net
Once again I would like to see the source code and possibly the documentation to make 100% sure you are testing a possible error code. I tried something like :
// needs install-package System.Management
ManagementScope sc = new ManagementScope();
ObjectQuery query = new ObjectQuery("select * from Win32_USBControllerDevice");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(sc, query))
{
using (ManagementObjectCollection result = searcher.Get())
{
System.Diagnostics.Debug.WriteLine("Devices: {0}",result.Count); // Shown on the output window
}
}
from an ASP.NET 3.1 Core (runs from VS on my machine) and it seems to find 41 devices (didn't expected that much). For now there is nothing pointing to ASP.NET Core not being able to find USB devices.
Also I would like to make sure it makes sense. As you are moving from a desktop app where the camera is attached to each and every client computer to a web app where the camera is attached to a remote web server I'm still in doubt that you are not trying
that just to realize later that it can't work. Edit: Or your intent is really to replace a desktop app with a web server on each and every machine??
A common catch when starting a web app is to NOT realize that you are in the very special case where your own machine is both the browser and the server side which can give the impression the web server can access local resources.
It runs and i get the same problem usb devices detected is zero
the. I’d start simple. As you know it works in a desktop app (.net I assume, you don’t give much info), create as simple classic .net command line project that can call the dll for usb device list. Once this working, check the dlls in the bin folder. Be
sure no config files are used.
now create a new .net core console app, and copy the code from above. Build it and check the bin folder has the required dlls.
note: you don’t tell much about the dll, but it’s probably c/c++ if callable from node. It will not throw an error only return error status from calls. Look at the node docs for debugging hints. If it’s callable by node you can call from .net core
I tried it with Console .net core and .net framework and it didn't detect the usb camera it only detects it in WinForm and WPF apps both .net framework and .net core.
Member
1 Points
48 Posts
How to access usb device using ASP.NET core
Apr 07, 2020 06:24 AM|algebgeo|LINK
I created a desktop app that control usb device now i want to convert the app to a webapp but the problem is the ASP.net core doesn't detect the usb device i tried many solutions but the same result the usb device and website are all in my pc i tried other technologies like node js and python django it worked fine on those but i want to do it in asp.net core any other solutions thanks in advance
Contributor
2690 Points
874 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 07:32 AM|Rena Ni|LINK
Hi algebgeo,
To detect the USB service,you could try to use `System.Management` package.
Reference:
https://stackoverflow.com/a/51806262/11398810
Best Regards,
Rena
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 07:40 AM|algebgeo|LINK
Thank you for your answer but i have the functions that can detect usb device it works well in the desktop app but when i try to run it in asp.net web app it doesn't work i tried using node js and it worked well but i want to use asp.net core
Contributor
2690 Points
874 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 07:58 AM|Rena Ni|LINK
Hi algebgeo,
It seems you want to make your previous code work in a new asp.net core project?If so,you need to share a sample.
Best Regards,
Rena
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 08:07 AM|algebgeo|LINK
its not a sample code its a DLL that have functions that access usb device i just want to map it to asp.net web app and make it work when i run those functions on asp.net they don't work i managed to work the DLL in node js but i want to make it work on asp.net core web app
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 08:16 AM|PatriceSc|LINK
Hi,
Always tell what actually happens rather than just that "it doesn't work". My guess is that this is server side code and so it tries to use a USB device that would be plugged on the server side (even if it may appear to work on your development machine).
Instead I would try https://developer.mozilla.org/en-US/docs/Web/API/USB
If you need further help the final goal could help (this is a usb drive, it is used for which purpose ???)
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 08:24 AM|algebgeo|LINK
What happens is the DLL have a function that returns the number of usb device connect to the PC it works fine in desktop app but when i run this function in asp.net app it returns 0 devices detected and its not a serverside code actually all things exist in my PC the web app and usb device so why asp.net web app cannot detect the usb device i gave all the permissions to the web app to access my devices.
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 08:58 AM|PatriceSc|LINK
And using a separate web server won't be your final architecture? If yes it won't work anyway once deployed.
Which kind of device is this? I can only assume the DLL does something wrong.
My first move would be to see if using WMI as shown at https://social.msdn.microsoft.com/Forums/en-US/8d81b8a3-c101-4b47-8274-dd743fa41ec4/get-devices-by-connection-as-in-device-manager?forum=csharpgeneral does detect something.
It runs from Visual Studio or is it deployed on your local IIS server?
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 09:04 AM|algebgeo|LINK
Its a usb camera and DLL is fine i tested it in node js app and i run it from visual studio
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 11:57 AM|PatriceSc|LINK
It really does nothing else than enumerating devices? If a 3rd party API what if you try their support site. I can only guess that there is an underlying error which is ignored rather than really not finding any device? The final goal is still unclear.
If you want to show in a browser images taken by a remote camera attached to a web server, AFAIK https://en.wikipedia.org/wiki/IP_camera are mots often used.
If you want to capture a video from a browser, you have browser side APIs to do this kind of capture.
All-Star
53001 Points
23594 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 12:12 PM|mgebhard|LINK
DLLs run on a web server not the client machine. The camera must be attached to the server's USB port.
Your USB camera might come with software installed on the client the allows streaming video. You'll need to read the documentation for the USB camera you are using or contact support for the camera to make sure the camera will work as expected. You'll certainly need to configure your network to allow a web server or other internet connected devices to see the camera images by connection to your machine. Your machine becomes a web server.
All-Star
58164 Points
15647 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 02:53 PM|bruce (sqlwork.com)|LINK
.net 5 will have better support of desktop features. Asp.net core can call c/c++ dlls, but not 4.8 libraries. Look at the c/c++ APIs.
i’d probably stick with node.
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 07, 2020 11:26 PM|algebgeo|LINK
The DLL have many APIs that control the camera and every thing run on my machine i cannot stick with node i have to make it with ASP.net core
All-Star
58164 Points
15647 Posts
Re: How to access usb device using ASP.NET core
Apr 08, 2020 12:47 AM|bruce (sqlwork.com)|LINK
If the dll has a c/c++ interface, which it probably does for node to call it, you should be able to call from c#
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 08, 2020 01:22 AM|algebgeo|LINK
yeah i am able to call it from c# desktop app and the functions work properly but from asp.net core i can call the functions and the functions work but they cannot detect the usb camera thats the problem.
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 08, 2020 12:32 PM|PatriceSc|LINK
You are 100% sure it doesn't return some error code you could check? What if you show the minimal amount of code showing that the camera is not detected? And so I would try on my own to see if it seems an ASP.NET Core side issue or rather a problem in this 3rd party DLL.
I'm still not sure what you'll do with a camera directly attached to a web server rather than to a browser side computer. You want to monitor the web server surrounding ?
If the web site will always run on the same computer to which a camera is attached it could be better to just keep your current desktop app rather than having to install a web server on each and every machine to do the same thing.
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 09, 2020 04:52 AM|algebgeo|LINK
I am sure that there is no errors it only doesn't detect usb camera the functions work properly but the problem is the detection of the usb camera there is no problem with the DLL and i don't have the source code of the DLL to show it and the code is simple i just use p/invoke to call the DLL and use its functions it works well in desktop apps but not in asp.net core or any asp.net
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 09, 2020 08:26 AM|PatriceSc|LINK
Once again I would like to see the source code and possibly the documentation to make 100% sure you are testing a possible error code. I tried something like :
from an ASP.NET 3.1 Core (runs from VS on my machine) and it seems to find 41 devices (didn't expected that much). For now there is nothing pointing to ASP.NET Core not being able to find USB devices.
Also I would like to make sure it makes sense. As you are moving from a desktop app where the camera is attached to each and every client computer to a web app where the camera is attached to a remote web server I'm still in doubt that you are not trying that just to realize later that it can't work. Edit: Or your intent is really to replace a desktop app with a web server on each and every machine??
A common catch when starting a web app is to NOT realize that you are in the very special case where your own machine is both the browser and the server side which can give the impression the web server can access local resources.
All-Star
58164 Points
15647 Posts
Re: How to access usb device using ASP.NET core
Apr 09, 2020 03:35 PM|bruce (sqlwork.com)|LINK
does the asp.net core fail if you run it from the command line (so it runs as your login)
dotnet run
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 09, 2020 11:07 PM|algebgeo|LINK
It runs and i get the same problem usb devices detected is zero
All-Star
48500 Points
18071 Posts
Re: How to access usb device using ASP.NET core
Apr 10, 2020 02:15 PM|PatriceSc|LINK
I would like to make 100% sure the code you are testing runs. What if you try to add:
if (result.Count==0) throw new Exception("no device");
Then do a last test. Do you see a "no device" exception?. If yes I hardly see what could block enumerating devices on your side.
And so on my side I tried a PowerShell command line prompt and I do find the same count:
All-Star
58164 Points
15647 Posts
Re: How to access usb device using ASP.NET core
Apr 10, 2020 05:50 PM|bruce (sqlwork.com)|LINK
the. I’d start simple. As you know it works in a desktop app (.net I assume, you don’t give much info), create as simple classic .net command line project that can call the dll for usb device list. Once this working, check the dlls in the bin folder. Be sure no config files are used.
now create a new .net core console app, and copy the code from above. Build it and check the bin folder has the required dlls.
note: you don’t tell much about the dll, but it’s probably c/c++ if callable from node. It will not throw an error only return error status from calls. Look at the node docs for debugging hints. If it’s callable by node you can call from .net core
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 11, 2020 01:43 AM|algebgeo|LINK
You got me wrong the code you sent me it detected 12 devices i was speaking of the DLL.
Member
1 Points
48 Posts
Re: How to access usb device using ASP.NET core
Apr 11, 2020 03:02 AM|algebgeo|LINK
I tried it with Console .net core and .net framework and it didn't detect the usb camera it only detects it in WinForm and WPF apps both .net framework and .net core.
Member
4 Points
261 Posts
Re: How to access usb device using ASP.NET core
Feb 16, 2021 09:46 AM|Kruddler|LINK
Try Usb.Net. It supports .NET Core and it works good.
The concept of a "Browser" is a design flaw of the internet.