-
Sep 10th, 2023, 01:26 PM
#1
Thread Starter
Lively Member
Error using My.Computer
With a Console Application with target framework .NET Framework 4.8 a statement of the form
Code:
My.Computer.FileSystem.WriteAllText(...)
works fine. But with one with target framework .NET 7.0 I get an error
Code:
{ } Namespace xx.My
BC30456 'Computer' is not a member of xx.My
(where xx is the name of the Application).
What do I need to do to fix this? Thanks!
Last edited by dday9; Sep 11th, 2023 at 09:17 AM.
-
Sep 10th, 2023, 01:53 PM
#2
Re: Error using My.Computer
Just forget all those My.* helpers and use the real classes. For your case it is System.IO.File.WriteAllText().
-
Sep 10th, 2023, 04:47 PM
#3
Thread Starter
Lively Member
Re: Error using My.Computer
Thanks. Yes that works. However I now have another problem. I believe the following statement works under .NET Framework 4.8:
Code:
My.Computer.Keyboard.SendKeys("x{ENTER}", True)
The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?
* https://learn.microsoft.com/en-us/do...owsdesktop-7.0)
Last edited by dday9; Sep 11th, 2023 at 09:17 AM.
-
Sep 10th, 2023, 08:56 PM
#4
Re: Error using My.Computer
There’s a SendKeys.Send(String) Method in System.Windows.Forms.dll, but you wouldn’t want to use that in a .Net. Core application
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 10th, 2023, 09:21 PM
#5
Re: Error using My.Computer
 Originally Posted by coffent
The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?
Of course the namespace exists but you're creating a Console application, so why would the required assembly be referenced? It shouldn't be a surprise that the System.Windows.Forms namespace contains types intended to be used in Windows Forms applications. Using SendKeys in a Console app is extremely dodgy as they are not GUI apps, so assuming a GUI is inappropriate.
Last edited by jmcilhinney; Sep 10th, 2023 at 09:26 PM.
-
Sep 10th, 2023, 09:26 PM
#6
Re: Error using My.Computer
 Originally Posted by coffent
With a Console Application with target framework .NET Framework 4.8 a statement of the form
My.Computer.FileSystem.WriteAllText(...)
works fine. But with one with target framework .NET 7.0 I get an error
{ } Namespace xx.My
BC30456 'Computer' is not a member of xx.My
(where xx is the name of the Application).
What do I need to do to fix this? Thanks!
.NET Core (.NET 5 and later are based on .NET Core) has been built from the ground up so anything it includes has been implemented from scratch. Most of what was available in .NET Framework has been reimplemented in .NET Core but not everything. VB support was initially poor in .NET Core and it was VB-specific functionality like the My namespace that held it up. The My namespace exists but doesn't include all the functionality that it did in .NET Framework. My does make some things easier but there's a lot of things that are really just duplication and this is one of them. That WriteAllText method has no real advantage over System.IO.File.WriteAllText so there seems little reason to use a VB-specific method when you use the same methods as a C# developer in so many other places. If you're going to use My at all then then really ought to use it everywhere you can or else you're making your code inconsistent. Personally, I might use it on a few occasions where it adds genuine value by simplifying some task but there are few examples of this.
-
Sep 11th, 2023, 08:55 AM
#7
Thread Starter
Lively Member
Re: Error using My.Computer
Thanks paul and jmcilhinney for your helpful responses. I'll have to rethink how I want to do this (as a very amateur programmer).
-
Sep 11th, 2023, 09:20 AM
#8
Re: Error using My.Computer
I get you're trying to write to a file and send some keys, but could you explain what it is you're actually trying to accomplish? I.e. what does the application you're writing do?
Answering that might help us help you better.
-
Sep 11th, 2023, 01:29 PM
#9
Re: Error using My.Computer
 Originally Posted by coffent
Thanks. Yes that works. However I now have another problem. I believe the following statement works under .NET Framework 4.8:
Code:
My.Computer.Keyboard.SendKeys("x{ENTER}", True)
The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?
* https://learn.microsoft.com/en-us/do...owsdesktop-7.0)
If this is a console app why aren't you using Console.Write or Console.WriteLine?
-
Sep 11th, 2023, 02:17 PM
#10
Re: Error using My.Computer
Well, for starters it isn't the same thing. Secondly, because it's not the same thing. And thirdly, I have no idea since as pointed out by JMC, sendKeys from a console app doesn't make much sense.
-tg
-
Sep 12th, 2023, 07:58 AM
#11
Re: Error using My.Computer
 Originally Posted by techgnome
Well, for starters it isn't the same thing. Secondly, because it's not the same thing. And thirdly, I have no idea since as pointed out by JMC, sendKeys from a console app doesn't make much sense.
-tg
So I was addressing the latter thinking that the OP was just writing to the Console.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|