Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Walked
Apr 14, 2003

Any suggestions for the most modern way to run PowerShell scripts from C#?

From what I can google, a lot of stuff is PS1.0 and .NET 2.0 and seems out of date.

Looking to run actual script files, ideally natively (so possibly read the PowerShell file contents and then execute that as a PowerShell object).

Any suggestions?

Adbot
ADBOT LOVES YOU

Mr Shiny Pants
Nov 12, 2012
So what do you guys do for storing passwords? I have a couple of certificates (pfx) that need a password to open, so I can't really store salted passwords. Somewhere I would need to store the password otherwise I can't sign new certs for other nodes in the network.

I don't want to store them in the cert manager otherwise it won't work on Linux. Any ideas? I am fine by storing them on disk, I mean if they have physical access to the machine the whole point is moot anyway. I was just wondering if some of you might have done something like this before.

raminasi
Jan 25, 2005

a last drink with no ice
I accidentally just wrote an event handler for A that caused event B to fire, which in turn had a handler that caused A to fire, but the resulting infinite loop didn't blow my stack. Is that as impressive of a runtime achievement is it seems?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

I accidentally just wrote an event handler for A that caused event B to fire, which in turn had a handler that caused A to fire, but the resulting infinite loop didn't blow my stack. Is that as impressive of a runtime achievement is it seems?

Not really, I think.

Events are async, so each handler will happily terminate and GTFO of the stack after firing off the event that continues the loop - kinda like TCO, in a way. In a normal infinite loop you blow the stack because there's an endless chain of calling functions that never got to terminate, but that doesn't happen here.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

ljw1004 posted:

PS. I'm due to give some Microsoft internal training talks on UWP app development in .NET, and the new CoreCLR and NuGet stuff. If you have further questions I'd love to hear them so I can incorporate the answers into my talks :). I'll make public versions of the talks too.

Here's a question: I don't understand how to target .NET Core in VS 2015. I had expected to see it in the framework dropdown on the 'New Project' screen, along with all the full .NET versions, but it's not there. I've googled but I don't know what the appropriate incantation is. This only shows command line tools. The 'More Frameworks' link doesn't say anything (and ps- the url implies I clicked this from 2013, but it was 2015).

Is this something that will only be possible after the 29th?

Factor Mystic fucked around with this message at 02:04 on Jul 26, 2015

raminasi
Jan 25, 2005

a last drink with no ice

NihilCredo posted:

Not really, I think.

Events are async, so each handler will happily terminate and GTFO of the stack after firing off the event that continues the loop - kinda like TCO, in a way. In a normal infinite loop you blow the stack because there's an endless chain of calling functions that never got to terminate, but that doesn't happen here.

I had never heard this before. Do you know somewhere I can read about it?

ljw1004
Jan 18, 2005

rum

Factor Mystic posted:

Here's a question: I don't understand how to target .NET Core in VS 2015. I had expected to see it in the framework dropdown on the 'New Project' screen, along with all the full .NET versions, but it's not there. I've googled but I don't know what the appropriate incantation is. This only shows command line tools. The 'More Frameworks' link doesn't say anything (and ps- the url implies I clicked this from 2013, but it was 2015).
Is this something that will only be possible after the 29th?

Today in VS2015 you can do File>New>C#>Web>ConsoleApp/ClassLibrary. These are still in preview.

As of July 29th you'll be able to do File>New>C#/VB>Windows>Universal>App/ClassLibrary.

Those are all the project types which take advantage of .NETCore. (That means: these app types pick up one of the .NETCore implementations of the .NET runtime, and they pick up the .NETCore implementations of the .NET framework, and they deploy them app-locally.) .NETCore hasn't yet made its way into any other project types. I don't think we'll see it as an option for regular desktop apps (Console, WPF, WinForms) for a while. That's because these project types all depend upon the very large .NET framework that's part of the OS, and includes things like WPF and Winforms, things that aren't in .NETCore.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

I had never heard this before. Do you know somewhere I can read about it?

Ok, sorry there, midnight brain fart, forget what I said.

I'm so used to putting events, particularly UI events, on async execution (event handlers just wrap a threadpool call) that I forgot it's not the default behaviour.

Event handler methods, by themselves, are blocking and synchronous.

There still could be several reasons why your loop didn't explode. Maybe one of the events only actually fires after the method is exited, maybe you're using WaitHandles in a way that prevents the problem... I'd like to see the code, to be honest.

ljw1004
Jan 18, 2005

rum

GrumpyDoctor posted:

I accidentally just wrote an event handler for A that caused event B to fire, which in turn had a handler that caused A to fire, but the resulting infinite loop didn't blow my stack. Is that as impressive of a runtime achievement is it seems?

The CLR JIT, particularly on x64, is quite happy to do tail-call optimization. That's when the last act of one method is to invoke another method, and it decides to simply re-use the callers stack frame rather than starting a new one. I wonder if this is happening?

(you can disable it with MethodImplOptions attribute on your method, or something like that).

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


I'm going nuts trying to sort this out in my head. In the MVVM pattern, are ViewModels expected to contain instances of their associated models, or should the actual data be stored/kept somewhere else? If the latter, what the hell should I be googling for?

The first is what I defaulted to trying to learn this, but then I wondered how the hell two viewmodels should be sharing data that they both need to work with. (I sort of alluded to this earlier with the Command question. Really dealing with having multiple viewmodels in general is what's killing me I think :saddowns:)

Mr Shiny Pants
Nov 12, 2012

Ciaphas posted:

I'm going nuts trying to sort this out in my head. In the MVVM pattern, are ViewModels expected to contain instances of their associated models, or should the actual data be stored/kept somewhere else? If the latter, what the hell should I be googling for?

The first is what I defaulted to trying to learn this, but then I wondered how the hell two viewmodels should be sharing data that they both need to work with. (I sort of alluded to this earlier with the Command question. Really dealing with having multiple viewmodels in general is what's killing me I think :saddowns:)

Ain't it grand? I usually encapsulate my model in my viewmodel, saves me from writing proxies. So I have a viewmodel that has a model as property, any properties set or get from the viewmodel will be get and set the from the model it contains. The setters in the viewmodel will INPC.

The problem with this is with collections, you have to write your own adder and remover functions if the model has no ObservableCollections in it.

A for viewmodel to viewmodel, use messages. In the MVVMlight toolkit you'll find a good messaging solution.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


I'm trying to avoid using outside toolkits or libraries, at least at work, because of the Internet thing (I could download it and drag a CD upstairs but :effort:). Is a good inter-VM messaging scheme much of a pain to write?

While I'm at home I'll take a look at MVVM Light, thanks :)

Ciaphas fucked around with this message at 22:51 on Jul 26, 2015

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

ljw1004 posted:

Today in VS2015 you can do File>New>C#>Web>ConsoleApp/ClassLibrary. These are still in preview.

As of July 29th you'll be able to do File>New>C#/VB>Windows>Universal>App/ClassLibrary.

Those are all the project types which take advantage of .NETCore. (That means: these app types pick up one of the .NETCore implementations of the .NET runtime, and they pick up the .NETCore implementations of the .NET framework, and they deploy them app-locally.) .NETCore hasn't yet made its way into any other project types. I don't think we'll see it as an option for regular desktop apps (Console, WPF, WinForms) for a while. That's because these project types all depend upon the very large .NET framework that's part of the OS, and includes things like WPF and Winforms, things that aren't in .NETCore.

"File>New>C#>Web>ConsoleApp/ClassLibrary" doesn't show .NET Core in the New Project window, but I see I can switch over to it in project properties. That's a bit weird but I can deal.

Not sure why normal desktop Console apps couldn't target .NET Core the way a "web" Console app can.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Ciaphas posted:

Is a good inter-VM messaging scheme much of a pain to write?

The concept isn't complicated, but there can be a lot of weirdness with garbage collection so you have to use WeakReference. Also, if you want your message subscriptions strongly typed (you do), then you have to deal with collections containing multiple generic types. It's annoying enough that you're probably better off picking up someone else's battle tested implementation.

Also who restricts a programmer's internet? That's just a guaranteed destruction of productivity.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Bognar posted:

The concept isn't complicated, but there can be a lot of weirdness with garbage collection so you have to use WeakReference. Also, if you want your message subscriptions strongly typed (you do), then you have to deal with collections containing multiple generic types. It's annoying enough that you're probably better off picking up someone else's battle tested implementation.

Also who restricts a programmer's internet? That's just a guaranteed destruction of productivity.

Sounds like :effort: is in favor of getting MVVMLight or some other library, then. Thanks. :)

Mr Shiny Pants
Nov 12, 2012

Ciaphas posted:

Sounds like :effort: is in favor of getting MVVMLight or some other library, then. Thanks. :)

From having used MVVMLight, it is not something you whip up in a day. It is a well respected library though.

Gul Banana
Nov 28, 2003

Factor Mystic posted:

"File>New>C#>Web>ConsoleApp/ClassLibrary" doesn't show .NET Core in the New Project window, but I see I can switch over to it in project properties. That's a bit weird but I can deal.

Not sure why normal desktop Console apps couldn't target .NET Core the way a "web" Console app can.

it's due to legacy and IP
the 'full' non-core framework is required for WPF, forms, etc because they are implemented in terms of windows-specific APIs. directx is used heavily, stuff like system.drawing uses GDI, system.web uses http.sys, etc.

the new core is open source and cross-platform- they don't want to open source and can't make cross-platform parts of the older stuff. asp.net 5 runs purely on the OSS code and can use things like IIS optionally as plugins. windows 10-specific (uwp) stuff runs on .net core + proprietary windows specific parts. it can be thought of as a refactoring of WPF so that the xaml layer exists 'above' the .net one.

(although this is an oversimplification and not actually true. uwp is really more like 'WPF reimplemented in c++/COM, with the environments including .net able to access its apis via 'projection' plugins. for windows 8, the .net projection was a custom vertical; now it is .net core)

clandestine cactus
Feb 5, 2009

Hot Rope Guy
Any ETA on Azure supporting 4.6?

epswing
Nov 4, 2003

Soiled Meat

clandestine cactus posted:

Any ETA on Azure supporting 4.6?

Apparently you shouldn't upgrade to 4.6, yet. :tinfoil:

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

Gul Banana posted:

it's due to legacy and IP
the 'full' non-core framework is required for WPF, forms, etc because they are implemented in terms of windows-specific APIs. directx is used heavily, stuff like system.drawing uses GDI, system.web uses http.sys, etc.

the new core is open source and cross-platform- they don't want to open source and can't make cross-platform parts of the older stuff. asp.net 5 runs purely on the OSS code and can use things like IIS optionally as plugins. windows 10-specific (uwp) stuff runs on .net core + proprietary windows specific parts. it can be thought of as a refactoring of WPF so that the xaml layer exists 'above' the .net one.

(although this is an oversimplification and not actually true. uwp is really more like 'WPF reimplemented in c++/COM, with the environments including .net able to access its apis via 'projection' plugins. for windows 8, the .net projection was a custom vertical; now it is .net core)

I know all that, perhaps you misinterpreted my statement. I'm not expecting that WPF or Winforms or a Full Desktop Console app be able to be targetted to .NET Core. I AM expecting that for certain project template types, I would be able to target .NET Core... for example, Console apps and Library (dll) projects as previously stated. This is part of where my confusion was, because even though "Web" Console/Library projects CAN target .NET Core, you CANNOT pick it from the "Framework" list in the New Project dialog. Furthermore, I'm not sure what differentiates a "Web" Console/Library project from a "Windows" Console/Library project except that the former can target .NET Core & the latter can't even though a "Web" Console/Library certainly will work on WIndows.

If I want to make a Console app that works on Windows and also works on Linux, and I want to build this thing in VS2015, currently I have to make a "Web" Console app targetted to Full .NET 4.6, then go into project properties and retarget it to .NET Core. This is confusing and irritating. Hence my question, why can't a "Windows" Console app retarget to .NET Core the way a "Web" Console app can. Is what's actually going on here a project file format selection? So if I go "Web" I get project.json and if I go "Windows" I get mything.csproj? And then what is changing on the 29th?

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

The 4chan-Boston-Marathon-witchhunt style debugger diagrams in the github issue are great.

ljw1004
Jan 18, 2005

rum

Factor Mystic posted:

If I want to make a Console app that works on Windows and also works on Linux, and I want to build this thing in VS2015, currently I have to make a "Web" Console app targetted to Full .NET 4.6, then go into project properties and retarget it to .NET Core. This is confusing and irritating. Hence my question, why can't a "Windows" Console app retarget to .NET Core the way a "Web" Console app can. Is what's actually going on here a project file format selection? So if I go "Web" I get project.json and if I go "Windows" I get mything.csproj? And then what is changing on the 29th?

The .NET Core "Console app" stuff currently in VS2015 is all still "PREVIEW" -- that's why it's confusing and irritating! there's just the bare minimum there at the moment to demonstrate things working end-to-end. What's changing on the 29th is

(1) One new .NET Core targets have been finished up, UWP. Also, UWP apps use .NET Native when you build them in "Release" mode.

(2) Another new .NET Core target has mostly been finished up, PCL. Plus the shims needed to get a .NET Core PCL working properly in non-.NETCore-projects. There are still a couple of rough edges in ".NET Core PCLs" regarding Project2Project references, but nothing show-stopping. Writing a "PCL which targets .NET46 + UWP" is another option you have now for writing a .NET Core class library.

(3) Technically as of July 29th you can use project.json in any project type, although there might be rough edges and it's not yet documented. I wrote a blog post about project.json and what it means for NuGet package authors:
http://blogs.msdn.com/b/lucian/archive/2015/07/27/writing-a-nuget-package-for-vs2015-rtm-and-uwp.aspx


As for what the next .NET Core target will be and when it will be done? I don't know. I do hope it's console apps because I love me some console apps, and the ASP.NET web console apps don't quite hit the spot for me.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Wow, that's a pretty big deal. A bug that only pops up in Release builds, with optimizations enabled, that silently passes incorrect parameters to methods.

EDIT: Oh, cool. It also affects 64-bit .NET 4.5 apps (maybe 4.0 too?), since installing 4.6 replaces the JITter for earlier framework versions.

Bognar fucked around with this message at 19:21 on Jul 27, 2015

raminasi
Jan 25, 2005

a last drink with no ice

Haha holy poo poo

I love how much emphasis he puts on how big a deal this is. I'm not really sure there's anyone who'd see "sometimes arguments are passed incorrectly" as anything other than a huge problem.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Yeah, wow. That's terrifying.

Dietrich
Sep 11, 2001

Wow now I'm wondering if I should hold off on upgrading to windows 10.

raminasi
Jan 25, 2005

a last drink with no ice
Does anyone know a good hand-holding introduction to C# for someone who's never programmed before?

Inverness
Feb 4, 2009

Fully configurable personal assistant.
I'll copy the recommendations section for reference:

quote:

  1. Do not install .Net 4.6 in production.
  2. If you have installed .Net 4.6, disable RyuJIT immediately (this is a temporary fix and should be removed when an update is released). You can disable RyuJIT via a registry setting (note: this requires an application pool recycle to take effect).
    • Under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework add a useLegacyJit DWORD with a value of 1
    • Or via PowerShell:
      code:
      Set-ItemProperty -Path HKLM:\Software\Microsoft\.NETFramework -Name useLegacyJit -Type DWord -Value 1
      
Be aware, the web.config method (#3) of disabling RyuJIT does not work. Outside of IIS hosting, applying this fix via app.config does work.

Mellow_
Sep 13, 2010

:frog:

GrumpyDoctor posted:

Does anyone know a good hand-holding introduction to C# for someone who's never programmed before?

Although C# wasn't my first language, I learned a lot from the C# Primer Plus.

Gul Banana
Nov 28, 2003

quote:

edit: removed my article, since the NuGet team are keen to explain this themselves in a few days -- can't wait!
:( well, I'm sure that writing it was educational at least

Tony Montana
Aug 6, 2005

by FactsAreUseless
Hello developers :)

You're pretty much a different bunch from the infrastructure crew, so it's possible I've never met any of you before.

I'm a long time infrastructure consultant, me and Microsoft are good friends. I've ended up writing a lot of VBScript (and now increasingly Powershell), scripting against Active Directory and making increasingly complex scripts until someone hired me to do just that.

I did MIS at Uni, not CS. I never wanted to be a dev, because I had ideas about what that meant and what the industry is like.. which were right but also pretty naive.

I am at a crossroads in my career, I'm 34 and at pretty much the pointy end of infrastructure. I'm really, really thinking about development as I think it suits my personality more.

.NET makes the most sense, it's in the Windows platform which I know a lot about.. I'm already really comfortable with VBS and Powershell and I even did some actual VB coding back in the day.

Anyone got some advice? Where to start? Should I do this? Yes, I earn a lot of money and work with big corporations.. are there developers who wish for these things and want to warn me to stay where I am?

I guess the biggest hurdle for me is getting that first real dev job and will my code suck because I don't have the formal CS training. I'm willing even to do that.. but it doesn't seem like a mandatory first step.

Why do I want to be a dev?
I want to be left alone to work on large problems, basically project work
I enjoy detail and am meticulous about comments in my own code and doing things in a way that doesn't create a loving mess
I enjoy the sense of accomplishment after writing something useful. Infrastructure can end up so soulless, you don't actually create anything and at least at the end of a day of scripting I can look at what I wrote and be proud.
I'm getting fed up with infrastructure types.. I know it's probably where I'm working now.. but brainless shitheads that should still be on the helpdesk. I want to work with IT professionals that really want to be here and be good at what they do, not just close tickets and collect pay.
I've got a lot of experience in the industry and that would translate to projects.. I know a lot about the Active Directory Scripting Interface, etc, so I'm not some kid who knows coding best practice but has never actually worked in commercial IT.

What do you think, .NET devs? Am I doing this for the right reasons?

Tony Montana fucked around with this message at 05:51 on Jul 28, 2015

Kekekela
Oct 28, 2004

Tony Montana posted:



What do you think, .NET devs? Am I doing this for the right reasons?

You may very well like development better but I think you need to temper your expectations with regards to a lot of this stuff, like:
- I want to be left alone to work on large problems, basically project work
- I enjoy detail and am meticulous about comments in my own code and doing things in a way that doesn't create a loving mess
- I want to work with IT professionals that really want to be here and be good at what they do

Gul Banana
Nov 28, 2003

just realised something rather sad- it looks like T4 isn't getting updated to C#6. i wanted to use elvis and so on in my templates :(

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
Re: Switching from IT to Dev:

You may find that you enjoy it more, you may find that you enjoy it less. Programmers can be dumb as a box of rocks, too. I'd start trying to learn by taking some scripts you've made and translating them into applications so you can get a feel for working with VS. You can also try hitting up any open source projects you use and going through the code base (maybe with a programmer buddy) to see what you can glean there.

Also, read a lot of books on data structures and algorithms.

Dietrich
Sep 11, 2001

Prefer self documenting code to well documented code.

code:
// get items to update
var l = q.Execute(a, b, c);

// loop through items
for(var x = 0; x < l.Length; x++)
{
 // set current status
 l[x].Status = d;
}
Will never be as easy to understand as

code:
var itemsToUpdate = getItemsFromOrder(customerId, clientId, ticketId);
for(var index = 0; index < itemsToUpdate.Length; index++)
{
  itemsToUpdate[index].Status = newStatus;
}
And when you're relying on comments to understand your code, you've got two things to maintain now rather than one.

Dietrich fucked around with this message at 14:44 on Jul 28, 2015

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Dietrich posted:

And when you're relying on comments to understand your code, you've got two things to maintain now rather than one.

code:
// do something when x is odd
if (x % 2 == 0) 
{
	DoSomething(x);
}
"Is the comment wrong or is that a bug?"

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Gul Banana posted:

just realised something rather sad- it looks like T4 isn't getting updated to C#6. i wanted to use elvis and so on in my templates :(

You mean they're dropping support? Link?

raminasi
Jan 25, 2005

a last drink with no ice

Dietrich posted:

Prefer self documenting code to well documented code.

code:

// get items to update
var l = q.Execute(a, b, c);

// loop through items
for(var x = 0; x < l.Length; x++)
{
 // set current status
 l[x].Status = d;
}

Will never be as easy to understand as

code:

var itemsToUpdate = getItemsFromOrder(customerId, clientId, ticketId);
for(var index = 0; index < itemsToUpdate.Length; index++)
{
  itemsToUpdate.Status = newStatus;
}

And when you're relying on comments to understand your code, you've got two things to maintain now rather than one.

Your second example has a bug :v:

Dietrich
Sep 11, 2001

GrumpyDoctor posted:

Your second example has a bug :v:

dammit i just edited it.

Adbot
ADBOT LOVES YOU

Kekekela
Oct 28, 2004
I'm loving all of this node.js/react/etc integration stuff coming down lately. The real beauty is that even if the implementations are off the mark it gives those of us in corporate IT departments the leverage to start using those technologies since "MSFT is doing it".

And yeah, code comments and other largely ceremonial things seem to be for some reason the trappings that new developers associate with "good code" that are in fact (usually) the opposite.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply