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
Mr Shiny Pants
Nov 12, 2012

EssOEss posted:

HttpWebRequest has been in .NET since the early days, whereas HttpClient is newer, so I would expect the former to be the lower level primitive - possibly HttpClient might be using HttpWebRequest internally (or at least some of the HttpClient implementations - there are several over the different .NET variations!).

Thanks, that is also what I thought. I only use the client when I need to POST some files, that is just waaaay nicer than doing it manually.

Adbot
ADBOT LOVES YOU

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Essential posted:

I learned something today that I wanted to share, just in case it helps anyone else. HttpClient should NOT be used in a using block, even though it implements IDisposable. This can cause some serious performance problems. For us, specifically we had an Azure Function that was scaling up in ways we couldn't understand. It turns out it was due to wrapping an httpclient in a using block. What can happen is it leaves ports open and can even utilize all ports and hang the system up while waiting to free up resources.

Many of you may already know this, but I wanted to share just in case. Here's the link I found originally on the issue: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ . Here is a link from Microsoft describing it: https://docs.microsoft.com/en-us/azure/architecture/antipatterns/improper-instantiation/

Yep! You're supposed to reuse the same instance for all requests. Problem is, many if not most parameters that should be per-request are per-client instead, and so you'll be forced to either pool your HttpClients or re-create them over and over. You'd think you could personalize requests at the message handler level, but nope, you're very limited in what you can do. It's a really poor design!

Essential posted:

I was mistaken in that I thought anything that implements IDisposable should always be in a using block.

It's correct, but incomplete: you should always be aware of the scope of the object, and call Dispose as soon as it goes out of scope. For per-function scopes, you have using; for scopes that live longer, for example a field in an object, you'll have to call Dispose yourself at the right time. At a minimum, you'll have to override the finalizer of the object that contains the IDisposable field, but often you'll have to make the containing object IDisposable as well

It'll come more naturally to you if you have already experience with manual memory management, e.g. with the RAII pattern of C++. It's no coincidence that C++/CLI turns destructors into implementations of IDisposable.Dispose, instead of finalizers

hackbunny fucked around with this message at 12:45 on May 24, 2018

ljw1004
Jan 18, 2005

rum

EssOEss posted:

HttpWebRequest has been in .NET since the early days, whereas HttpClient is newer, so I would expect the former to be the lower level primitive - possibly HttpClient might be using HttpWebRequest internally (or at least some of the HttpClient implementations - there are several over the different .NET variations!).

My information is three years out of date but came from the authors+maintainers of HttpClient. They said that best practice at that time was to have just a singleton HttpClient in your code and re-use it for everything, so that caching and stuff could work as well as possible. (that wasn't possible in some cases where you customized it, but the principle remained that you should use as few instances as possible).

And like you say, they confirmed there were different implementations of HttpClient across the different .NET platforms. I know for sure that UWP had an implementation that's as close-to-the-metal of Win10 as possible. I believe that HttpClient got into .NETCore before HttpWebRequest, so I'd expect on that platform that it'd be the other way round.

LongSack
Jan 17, 2003

Given an ObservableDictionary<long, List<string>>, is there a good way in the MVVM model to populate a TabControl so that each tab has the key as the header, and say a ListBox populated by the Value as the contents? Using code-behind, I manually built the TabItems from the dictionary, and created a ListBox from the values as the child of each tab.

The scenario is that I have firewall rule dump files created from a shell script that I need to reformat into an excel spreadsheet. The files are named YYYYMMDD_<firewall name> so I want to group all the files with the same date since they are most likely the ones the user is interested in.

I’d like to use a TabControl to group dump files by date, but failing that will fall back to a ListView with entries ordered by date descending.

Edit: never mind, I ended up going with the ListView in descending date, ascending name order. This allows multiple selection on different dates, if needed. I bind the ListView’s SelectedItems property to the CommandParameter for my two build buttons, and it works quite well, even if the presentation is a bit boring.

LongSack fucked around with this message at 00:36 on May 26, 2018

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

nielsm posted:

Speaking of HTTP clients, as far as I can tell HttpWebRequest is the only way to use NTLM authentication with the current credentials? Is that right?

If you're using HttpClient you can specify using DefaultCredentials and this will work with 'windows' authentication in IIS. It'll be NTLM or whatever the fallback is

His Divine Shadow
Aug 7, 2000

I'm not a fascist. I'm a priest. Fascists dress up in black and tell people what to do.
Is it just me or is the code formatting in Visual Studio 2017 community edition really weird, at least for bog standard HTML coding, it does javascript and c# fine. I'm used to the old 2010 edition and it always formatted HTML code really well. But in the 2017 edition it's completely different. I've googled the gently caress out of this and tried all the tips on stackoverflow etc to tweak the formatting.

Now after all that it seems to indent tags in a proper manner and adds line breaks automatically, but say I got a <p> tag with text, all the text after the first line break will not be indented to match the rest of the block. This is bugging the hell out of me.

mortarr
Apr 28, 2005

frozen meat at high speed
I've got to build a windows app to manage bulk-uploading documents from windows pc's to a web-based document store, but I've not built a windows ui since my borland delphi and vb6 days.

I'm looking at c#/WPF and Neutronium so I can at least partially leverage my html/js/etc skills. Does this sound at all reasonable - I build asp.net mvc web apps, console apps and all kind of oddball integrations for my day job, deliberately keeping out of windows ui dev for the longest time, so I don't really know if this is a good choice or not.

My end goal is to have admins be able to customise some of the ui with a dsl or json template - I've done a similar thing on websites before, but ui on the web is a lot easier to control than I remember winforms being, so I'm not sure if WPF is a good fit, if Neutronium makes sense in this scenario, or if I'm setting myself up for failure.

Mr Shiny Pants
Nov 12, 2012

mortarr posted:

I've got to build a windows app to manage bulk-uploading documents from windows pc's to a web-based document store, but I've not built a windows ui since my borland delphi and vb6 days.

I'm looking at c#/WPF and Neutronium so I can at least partially leverage my html/js/etc skills. Does this sound at all reasonable - I build asp.net mvc web apps, console apps and all kind of oddball integrations for my day job, deliberately keeping out of windows ui dev for the longest time, so I don't really know if this is a good choice or not.

My end goal is to have admins be able to customise some of the ui with a dsl or json template - I've done a similar thing on websites before, but ui on the web is a lot easier to control than I remember winforms being, so I'm not sure if WPF is a good fit, if Neutronium makes sense in this scenario, or if I'm setting myself up for failure.

Maybe Electron? They ( MS ) use it to build VS Code.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
Electron is cool, but if you don't need your application to run on multiple platforms it seems like overkill.

If you need to run on Windows and you can't do a web app for business reasons, I would just go check out UWP. You can write UWP with C# and XAML or JavaScript and HTML.

https://docs.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide

mortarr
Apr 28, 2005

frozen meat at high speed

Calidus posted:

Electron is cool, but if you don't need your application to run on multiple platforms it seems like overkill.

If you need to run on Windows and you can't do a web app for business reasons, I would just go check out UWP. You can write UWP with C# and XAML or JavaScript and HTML.

https://docs.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide

poo poo, I hadn't even thought of a store app, that might be a better option than what I was looking at.

mystes
May 31, 2006

What was the library for .net framework that was similar to the new channel<T> for .net core but presumably not as performant? It was something that Microsoft made a while ago but (I think) never bothered actually bundling with .net. I can't remember and I'm having trouble googling it.

I just tried messing around with channel<T> and it seemed pretty nice but then I realized that System.Threading.Tasks.Dataflow was better for what I was doing. (Incidentally I think someone said that Microsoft might be planning on redoing the Dataflow library based on channel<T> in the future though.)

roadhead
Dec 25, 2001

roadhead posted:

.NET Core 2
.NET Framework 4.6.1
TFS Version 16.122.27409.2
Visual Studio is 2017 15.5.6

I have a Solution with three active projects in it.

A .NET Core Model, a WPF UI, and Unit Tests.

I wanted logging, so I look to see which Nuget package has the most downloads.

log4net, sounds great, love that apache license.

Builds fine on my machine, no problems.

Builds fine on the other developer's machines.

Doesn't build on TFS. Because it can't find the log4net reference. w t f.

Restore Nuget is in the tasks, but its only restoring it in the .NET Core Model project, not the UI WPF project where I actually want it?

nuget.Config is in play but has all the same sources that my local machine has, since I'm the one who checked it into git.

Just looking for some hints on places to look...

It's actually more embarrassing than you could possibly imagine. All the half-started projects that have been checked into this repo but also removed from the solution? Yea turns out * finds all those and tries to build them, so let that be a lesson, actually read the entire log and don't assume you know what it says. The projects I cared about were building fine, it was the abandoned garbage ones I forgot were even there that were failing.

EssOEss
Oct 23, 2006
128-bit approved
You should stop checking in poo poo that doesn't belong.

Shy
Mar 20, 2010

Is there a way to create publishing options for plain .net framework console applications that would copy build output to a predetermined ftp location or a local directory, like web apps? The only option VS offers me is ClickOnce which doesn't look good. I could simply copy it myself but the task is to simplify the process so that me and other developers could deploy different configurations without loving up configs and locations over and over again.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Shy posted:

Is there a way to create publishing options for plain .net framework console applications that would copy build output to a predetermined ftp location or a local directory, like web apps? The only option VS offers me is ClickOnce which doesn't look good. I could simply copy it myself but the task is to simplify the process so that me and other developers could deploy different configurations without loving up configs and locations over and over again.

Build it into your CI/CD pipeline. If you don't have one, you almost certainly should.

Shy
Mar 20, 2010

It's a cool idea that was suggested in the company earlier but we're a small data-centric shop with little actual development so right now it sounds like too much work (nobody has the right experience) for little gain, but there are many situations where a little help with manual binary pushing would be very useful.

EssOEss
Oct 23, 2006
128-bit approved
It is very simple, especially if you use Microsoft's team tools (TFS or VSTS). Just spend a few hours and do it.

raminasi
Jan 25, 2005

a last drink with no ice
dotnet publish might work with netframework apps in addition to netcore ones, I'm not sure. But really, just set up CI/CD. It's an incredible productivity multiplier, even for tiny projects.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
The person you're talking to likely doesn't have the clout to make that kind of call and is asking for alternative paths...

Red Mike
Jul 11, 2011

Shy posted:

Is there a way to create publishing options for plain .net framework console applications that would copy build output to a predetermined ftp location or a local directory, like web apps? The only option VS offers me is ClickOnce which doesn't look good. I could simply copy it myself but the task is to simplify the process so that me and other developers could deploy different configurations without loving up configs and locations over and over again.

Post-build task using robocopy or a simple script you write and build configurations. Simplest to set up.

If you don't want it tied to a build, you can write the script then add a "Custom Tool" that shows up in the tools menu and you can run manually.

epswing
Nov 4, 2003

Soiled Meat
OK this is just Bananas.

Sometimes when this form POSTs, things are received just fine in the ASP controller:


Sometimes, some random unicode character is appended. The JS console seems to think everything is fine:


Here's another random unicode character appended to the form value:


Seriously wtf.

Edit 1:
Only seems to be happening on Edge.
It's really keeping our software dept on Edge.
It doesn't pay to be at the bleeding Edge of technology.
I'm pretty much at the Edge of my rope?

Edit 2: ah there's the Edge bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/17358578/

quote:

When submitting ASP forms using <select><option>tags, the resulting data has an extra character on the end breaking data integrity. This did not happen in 1803, and does not happen in IE or Chrome.

quote:

We won’t stop the Windows update based on this problem. However, a fix has already been written, and servicing is in progress. I’m not the person responsible for the team writing the servicing fix, but I think the update should be part of the next patch Tuesday, which is (I think) due on the second Tuesday of the month of June.

quote:

Just to give everyone an update, it looks like when I was told the fix would make it to the next Patch Tuesday, the dev team meant the July patch tuesday and not the June patch tuesday.

epswing fucked around with this message at 15:42 on Jun 26, 2018

EssOEss
Oct 23, 2006
128-bit approved
Hey man, forms are such a new addition to HTML that it is totally normal for a browser to break them and schedule a patch for "some months or whenever".

On the upside, it's not like any users are affected because, of course, it's Edge.

Mr Shiny Pants
Nov 12, 2012
Does anyone actually use Edge? For as long as it's out I've only used it to download Firefox or Vivaldi.

epswing
Nov 4, 2003

Soiled Meat

EssOEss posted:

On the upside, it's not like any users are affected because, of course, it's Edge.

Mr Shiny Pants posted:

Does anyone actually use Edge? For as long as it's out I've only used it to download Firefox or Vivaldi.

Corporate client, they only have Edge and IE installed, and this can't be changed.

That bug report suggests this:
code:
<select>
    <option value="one">one</option>
    <option value="two">two</option>
</select>
is better than this:
code:
<select>
    <option>one</option>
    <option>two</option>
</select>
Apparently if you specify the value in both the value attribute and the element contents, the problem goes away (for some people?).

bigmandan
Sep 11, 2001

lol internet
College Slice

epalm posted:

Corporate client, they only have Edge and IE installed, and this can't be changed.

That bug report suggests this:
code:
<select>
    <option value="one">one</option>
    <option value="two">two</option>
</select>
is better than this:
code:
<select>
    <option>one</option>
    <option>two</option>
</select>
Apparently if you specify the value in both the value attribute and the element contents, the problem goes away (for some people?).

Isn't specifying the value the better way to do it in the first place regardless of the bug?

EssOEss
Oct 23, 2006
128-bit approved
I would not call it objectively better - both ways are valid HTML. The long form just allows the option value to differ from the option text, whereas in the short form they are the same.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

epalm posted:

Corporate client, they only have Edge and IE installed, and this can't be changed.

That bug report suggests this:
code:
<select>
    <option value="one">one</option>
    <option value="two">two</option>
</select>
is better than this:
code:
<select>
    <option>one</option>
    <option>two</option>
</select>
Apparently if you specify the value in both the value attribute and the element contents, the problem goes away (for some people?).

That's how you should do it anyway.

necrotic
Aug 2, 2005
I owe my brother big time for this!

a hot gujju bhabhi posted:

That's how you should do it anyway.

That doesn't excuse the bug, as it is perfectly acceptable HTML.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

necrotic posted:

That doesn't excuse the bug, as it is perfectly acceptable HTML.

Which they said is fixed, right?

My biggest issue with Edge is that updates are tied to OS releases and updates, rather than pushed through the store. If there was a way to do that, they could have got the fix out sooner rather than have to wait for a patch tuesday.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Fixed next month


quote:

Just to give everyone an update, it looks like when I was told the fix would make it to the next Patch Tuesday, the dev team meant the July patch tuesday and not the June patch tuesday

EssOEss
Oct 23, 2006
128-bit approved
After first being reported almost two months ago.

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
Is there a Roslyn extension that will add a blue squiggly or compiler warning if you're in an async method and calling foo.Bar() when foo.BarAsync() exists?

I'm updating a fairly large application which hardly made any use of async/await, when there's a lot of places where it could have been used, so one of the things I'm doing is trying to add in as much async as possible. This is going well in our own code since return types are changing and method names are being changed to ****Async, but I've noticed we're missing a couple of spots at the framework level, e.g. we've converted a method to async, and changed the calls to our own methods to await the new Async versions instead, but there are some spots where we'd call db.SaveChanges() where we should now await db.SaveChangesAsync() instead.

I know it's not going to catch everything, but it would still be a nice helper since the Foo/FooAsync naming convention is fairly standard. Alternatively, would anyone have any references to help me build an analyzer that would do this?

e: this looks like it might be a good starting point
edit2: this looks like it does exactly what i want

beuges fucked around with this message at 14:30 on Jun 29, 2018

ljw1004
Jan 18, 2005

rum

beuges posted:

Is there a Roslyn extension that will add a blue squiggly or compiler warning if you're in an async method and calling foo.Bar() when foo.BarAsync() exists?

Another extension I love is this: if you're in an async method which accepts a CancellationToken, and you invoke an async method which accepts an optional CancellationToken but you fail to provide it, then it emits a warning.

raminasi
Jan 25, 2005

a last drink with no ice
What am I misunderstanding about parsing non-English dates? This returns true on my local machine but not our test server or dotnetfiddle:
C# code:
DateTime.TryParse(“19-ene-2018”, new CultureInfo(“es-ES”), DateTimeStyles.None, out var result);

EssOEss
Oct 23, 2006
128-bit approved
CultureInfo behavior depends on the culture data installed in the operating system - it is not a constant. Not sure if it explains this particular instance but maybe a starting point.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

necrotic posted:

That doesn't excuse the bug, as it is perfectly acceptable HTML.

I never said it excused the bug but okay?

chippy
Aug 16, 2006

OK I DON'T GET IT
Am I going mad, or is there no simple 'Greater Than' data annotation in ASP.NET? There's Range, and the Data Annotations Extensions library has Min and Max but I can't use that any of those to do greater than zero on a decimal property. Why the gently caress is this not a thing?

I realise I can write one but I feel like this is such a simple thing that I shouldn't have to.

Munkeymon
Aug 14, 2003

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



chippy posted:

Am I going mad, or is there no simple 'Greater Than' data annotation in ASP.NET? There's Range, and the Data Annotations Extensions library has Min and Max but I can't use that any of those to do greater than zero on a decimal property. Why the gently caress is this not a thing?

I realise I can write one but I feel like this is such a simple thing that I shouldn't have to.

How is Min(0) not working for you for 'greater than 0'?

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Munkeymon posted:

How is Min(0) not working for you for 'greater than 0'?

Presumably Min(0) would allow zero itself.

The easiest workaround would be to define a const that contains the smallest possible positive decimal value, which is 1/(10^28), and use that with Min.

C# code:
class MyClass
{
	const decimal Epsilon = 1e-28M;

	[Min(Epsilon)]
	public decimal MyProperty { get; set; }
}
However, if you're using the error messages that are automatically generated with the data annotations this will probably make it say something stupid like 'X must be at least 0.0000000000000000000000000001', so in that case you may want to go the extra mile and make the GreaterThan attribute yourself. Keep in mind that if you're using these for client side validation you'll have to make a suitable JavaScript implementation as well. The potential hairyness of that might be the reason this doesn't exist to begin with.

Adbot
ADBOT LOVES YOU

Essential
Aug 14, 2003
If you were to build your first phone app, as a fun hobby project, what would you do? Go native? Xamarin?

I've been sort of burned out on my day in and day out programming job and find I've been spending too much time playing video games to wind down. I'd like to instead try building something new/fun as a more productive use of my time. I haven't done ANY phone app development so not sure where the best place to start is.

My guess would be xamarin, but I don't know if there are any gotcha's I should be worried about. Obviously c#/.net dev platform is a huge, huge bonus there.

Any advice or insight anyone has so I can stop procrastinating is really appreciated.

Essential fucked around with this message at 16:57 on Jul 7, 2018

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