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
Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm trying to expose .NET assemblies to my scripting runtime now and I'm surprised I'm not finding things inside of them that I'd expect. The trial is to expose System.Environment. I load an assembly for the System namespace just fine. The thing is that "Environment" doesn't show up in the assembly's GetTypes() nor exported types. Where do I have to go to locate it?

Adbot
ADBOT LOVES YOU

EssOEss
Oct 23, 2006
128-bit approved
It is documented. https://docs.microsoft.com/en-us/dotnet/api/system.environment?view=netcore-3.1



System.Runtime.Extensions for .NET Core 3.1. For .NET Framework it is in mscorlib.

Note that the locations of classes may change between runtime versions when Microsoft decices to spice up things.

You can also just do typeof(whatever).Assembly and find out what it returns if you want to manually poke around.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
That's a bit of a headscratcher. I was following an example of IronPython's CLR module and it's able to associate it with System like you would when typing it out as code. It automatically includes System and mscorlib as references so I shouldn't be surprised it's finding Environment in general. However, I can't figure out what's deducing where to look for it in a statement like "from System import Environment." If I went with System being the assembly name then I'm not going to find it.

I'm asking online because I'm having a hell of a time stepping through IronPython and inspecting Python.NET (since it has similar), but my first thought was to try to inspect existing examples.

EssOEss
Oct 23, 2006
128-bit approved

Rocko Bonaparte posted:

However, I can't figure out what's deducing where to look for it in a statement like "from System import Environment."

It has to look at every single referenced assembly. There is no relationship between type names (namespaces) and assemblies. If all you have is the type name (with namespace), you have no choice but to look at every candidate.

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
such a minor thing, but it bugs me - does anyone know a way to get VS Code to prefix readonly properties with an underscore? my main issue is that I was previously a heavy user of the constructor shortcut you could use where you declare the constructor parameter and then tell VS Code (or Visual Studio) to create a readonly property to store that parameter. So the code would go from this:
C# code:
public class PoopClass
{
    public PoopClass(string someString)
    {
        
    }
}
To this:
C# code:
public class PoopClass
{
    private readonly string _someString;

    public PoopClass(string someString)
    {
        _someString = someString;        
    }
}
Visual Studio did this with the leading underscore for the readonly field, but VS Code doesn't, so you end up with this:
C# code:
public class PoopClass
{
    private readonly string someString;

    public PoopClass(string someString)
    {
        this.someString = someString;        
    }
}
I notice Visual Studio doesn't do it with an underscore anymore, so either ReSharper was actually the thing doing it or Visual Studio changed - either way, I was able to reconfigure it in Visual Studio just fine.

In VS Code however, all I've found through Googling is some advice to use this editor config:
code:
[*.{cs,vb}]
dotnet_naming_rule.private_members_with_underscore.symbols  = private_fields
dotnet_naming_rule.private_members_with_underscore.style    = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds           = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _
This does entirely gently caress all. No noticeable change. Anyone know what the magic combination of settings are to get this to work?

Edit: I should have tried re-Googling this before posting - somehow this time I managed to find the answer right away. OmniSharp does not support editorconfig by default, you need to enable it in your settings.json:
code:
"omnisharp.enableEditorConfigSupport": true

putin is a cunt fucked around with this message at 23:29 on Apr 29, 2020

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

EssOEss posted:

It has to look at every single referenced assembly. There is no relationship between type names (namespaces) and assemblies. If all you have is the type name (with namespace), you have no choice but to look at every candidate.

Okay I see it now. I wish I didn't; that's another layer of onion I get to peel when doing lookups.

adaz
Mar 7, 2009

namlosh posted:

Did log4net fall out of favor? That’s what we use, but we just write to disk and the windows event log.

That said, we’re a bank and generate a LOT of logs. Like our little group generates many GB of logs a day using the RollingFileAppender which then has to be archived for like 5 years or something for audit

Don't mean to NECROPOST but in case you missed it log4net is officially dead and not supported. It caught me by surprise this week.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

adaz posted:

Don't mean to NECROPOST but in case you missed it log4net is officially dead and not supported. It caught me by surprise this week.

Wow that's a hell of a thing to do on April 1st. Are all the cool kids using something else?

(No points for the assholes that were about to respond, "Yeah, F#." You know who you are, even if I don't.)

Xik
Mar 10, 2011

Dinosaur Gum
Every app at our place uses nlog, setup of various targets (file, db, event) is pretty trivial, it does rolling archiving and other commons features, never had any problems.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
So I searched all my referenced assemblies for everything matching the given namespace and managed to then successfully find what I wanted and bind to it in my scripting runtime. I just want to say I was not very happy doing it! :mad: I just can't help but feel that's going to be slow and I'll have to do some optimization for it later, but that's for later.

Xik posted:

Every app at our place uses nlog, setup of various targets (file, db, event) is pretty trivial, it does rolling archiving and other commons features, never had any problems.

I think this is probably explaining more about me than anything else, but I just vaguely deciding nlog didn't have the features I wanted back when I was comparing it against log4net a whole... seven years ago or whatever it was. So yeah, okay, maybe that's changed!

adaz
Mar 7, 2009

Rocko Bonaparte posted:

Wow that's a hell of a thing to do on April 1st. Are all the cool kids using something else?

(No points for the assholes that were about to respond, "Yeah, F#." You know who you are, even if I don't.)

Like Xik I switched everything to Nlog. Serilog also has some buzz but Nlog had better documentation. It was trivial more or less drop in replacement for Log4net.. also was really nice having something that just had a bunch of nicely setup targets (log4net appenders) basically.

adaz fucked around with this message at 08:19 on Apr 30, 2020

raminasi
Jan 25, 2005

a last drink with no ice
We suspect that new third-party library we're using is causing five-second pauses in the finalizer thread. It's at least one of and possibly all three of their bug, our bug, and a BCL documentation bug, but we're not sure which. This isn't a question, I just wanted to share it because it's so weird and obscure.

Boz0r
Sep 7, 2006
The Rocketship in action.
How much do you guys use observer pattern? I've only really used it in games, but I've run into a few places in our asp.net web apps where it would make my life easier, but I've never seen anyone use it before.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Boz0r posted:

How much do you guys use observer pattern? I've only really used it in games, but I've run into a few places in our asp.net web apps where it would make my life easier, but I've never seen anyone use it before.

I don't think it's too much of a stretch to say that anybody using events in .NET is using that pattern. It can be more formalized, sure. So yeah, I'd say we're all soaking in it.

Boz0r
Sep 7, 2006
The Rocketship in action.
How much logic do you guys think is too much in a catch statement? I've found a try/catch that tries to call an external service and in the catch it makes several calls to CRM. The structure sort of makes sense, but I've always treated the catch block as a place to only log and/or decorate exceptions.

nielsm
Jun 1, 2009



Anything that could itself fail should not be in a catch block. (Assume logging can't fail, if logging fails it's fine to explode violently.)

B-Nasty
May 25, 2005

Boz0r posted:

How much logic do you guys think is too much in a catch statement? I've found a try/catch that tries to call an external service and in the catch it makes several calls to CRM. The structure sort of makes sense, but I've always treated the catch block as a place to only log and/or decorate exceptions.

Yeah, I agree with nielsm that you should be doing the minimum possible in a catch. I've had some difficult to track down bugs where something in a catch block was throwing an exception, which either hits a try/catch further up the stack or bubbles all the way to an unhandled exception. Many logging libraries (e.g. NLog) fail silently by default and catch any internal exceptions from something like trying to ToString a null object in a message formatter.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
Had a nice bug the other day where an Exception class constructor was calling an external service (and the call was failing).

SirViver
Oct 22, 2008

Eggnogium posted:

Had a nice bug the other day where an Exception class constructor was calling an external service (and the call was failing).
Clearly this should've been placed in the finalizer instead :hehe:

Nostalgamus
Sep 28, 2010

I've got a problem I'm struggling to figure out, and my Google skills are failing me.

An old application I'm responsible for maintaining (VB.NET) has started getting "Access denied" errors when writing files to the temp folder. When the user showed this off, he also demonstrated how he got the same message when trying to save files to his Documents folder. I have been unable to reproduce this when running/debugging the application on my computer.

The symptoms make it seem like the application is not running with the user's permissions, but I'm not seeing a way that's possible. It generally doesn't need to run as administrator (anymore), and I didn't see any UAC popup when the user was demonstrating the error. Besides, if the application was running as a separate admin user, I assume it would use that user's temp folder instead (and the path in the error message used the regular username, as far as I could tell).

One of the weird things is this problem first appeared in march, and then vanished after about a week, before popping up again earlier this week. Windows updates have been a theory, but I don't see how that could mess with permissions.

Any ideas on what could cause something like this? It might technically be a Windows issue, not a .NET one

(Oh, and if anyone's wondering: Yes, the application gets Errors, because most of the code was autoconverted from VB6 and hasn't been touched since.)

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Boz0r posted:

How much logic do you guys think is too much in a catch statement? I've found a try/catch that tries to call an external service and in the catch it makes several calls to CRM. The structure sort of makes sense, but I've always treated the catch block as a place to only log and/or decorate exceptions.

I'll counterpoint that they could be acceptable in certain contexts if it's performing some kind of recovery. I treat exceptions as a way of getting around:
code:
errno = do_thing1(...);
if(errno > 0)
{
   blablabla return > 0
}
...over and over and over and over. However, sometimes the error number implies a scenario where I have some agency to do a recovery. The more proper thing to do in this case is to check first before doing, but the API I'm working with doesn't always give a luxury like that.

NihilCredo
Jun 6, 2011

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

Boz0r posted:

How much logic do you guys think is too much in a catch statement? I've found a try/catch that tries to call an external service and in the catch it makes several calls to CRM. The structure sort of makes sense, but I've always treated the catch block as a place to only log and/or decorate exceptions.

Twelve years later and this essay is still my Bible when it comes to writing error-handling code.

It doesn't quite get into your question, but I take the 'exogenous exception' concept to mean one thing: that try/catch blocks should be as small as possible, and focused on the actual "dirty" IO call, GetResponse() or whatever, where try/catch is the only reliable error handling tool. Otherwise the error should be included as part of the normal control flow, with ifs or switches or pattern matching or dynamic dispatch or whatever.

(And incidentally - if I make an HTTP call, an exception should only be called in the case of an actual connection failure or malformed response: an HTTP 4xx or 5xx error should not throw.)

As I often mention I'm a F# guy, where try/catch is a single expression, so the try block and the catch block must return the same type. This leads naturally to very small error handlers:

code:
let butts = 
   try
      buttService.fetchButts()
   with ex -> 
      alert("Butt service unavailable! No butts will be used")
      // return empty butt collection		
      []

for butt in butts do clapCheeks(butt)		

Jewel
May 2, 2009


Ah this owns, very nice

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

NihilCredo posted:

(And incidentally - if I make an HTTP call, an exception should only be called in the case of an actual connection failure or malformed response: an HTTP 4xx or 5xx error should not throw.)

Yeah, this drives me up the wall. As someone who works in the testing space it’s super annoying when my tools think “obviously you’ll always expect a 200, right?”

EssOEss
Oct 23, 2006
128-bit approved
Counterpoint, JavaScript fetch() treats 400 as a success and it drives me up the wall when my code has to separately handle "the request failed because TCP connect failed" and "the request is failed because it was a 404 or something". In many cases, I really don't care and just want to log the exception and switch to the recovery path.

EssOEss
Oct 23, 2006
128-bit approved

Nostalgamus posted:

An old application I'm responsible for maintaining (VB.NET) has started getting "Access denied" errors when writing files to the temp folder. When the user showed this off, he also demonstrated how he got the same message when trying to save files to his Documents folder. I have been unable to reproduce this when running/debugging the application on my computer.

Try running Sysmon and capturing a trace of when this happens. You'll get a nice listing of every filesystem call and what happened. Be sure to open the detailed properties of the call once you find the failure in the main Sysmon listing, to see all the low level details associated with it. This usually helps a lot when dealing with filesystem gremlins.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

EssOEss posted:

Counterpoint, JavaScript fetch() treats 400 as a success and it drives me up the wall when my code has to separately handle "the request failed because TCP connect failed" and "the request is failed because it was a 404 or something". In many cases, I really don't care and just want to log the exception and switch to the recovery path.

Different contexts might prefer different defaults but I still feel righteous because:
1) it is simpler to write a wrapper that converts a non-exception response to an exception response than vice versa
2) the job of an http client library is to send a request and get a response, not to interpret the meaning of that response

NihilCredo
Jun 6, 2011

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

Also, the recovery path for a 4xx error is fundamentally different from the recovery from a connection error. It indicates a problem with the request, and you should immediately do something about it (eg. 403 = ask the user to re-insert credentials, 404 = tell the user that the thing does not exist); with a connection error you just want to show a progress bar and retry for as long as the user is willing to wait. You don't want to retry a 4xx unless you've changed your request.

It actually looks very strange to me that you want to treat them the same.

Atoramos
Aug 31, 2003

Jim's now a Blind Cave Salamander!


Curious if anyone has experience with downscaling images in .Net Core. I ran into a few pictures that System.Drawing doesn't like, and played around with a bunch of libraries. Photosauce.MagicScaler seems to be great and produces much better results than System.Drawing for the downscaling I'm doing, but the results still look notably worse than the native downsizing Firefox or Chrome performs when I just resize an image down using CSS. Here's the settings I end up feeding into MagicScaler:

code:
            var settings = new ProcessImageSettings
            {
                Height = 200,
                SaveFormat = FileFormat.Png,
                BlendingMode = GammaMode.Linear,
                Interpolation = InterpolationSettings.Lanczos,
                ResizeMode = CropScaleMode.Stretch,
                HybridMode = HybridScaleMode.FavorQuality
            };
Tried a number of interpolation settings, Lanczos seems to be much better than the other options available but still notably worse than the default downsizing performed in-browser and I'm not sure why that would ever be the case.

Edit: Also tried SixLabors.ImageSharp which is another very popular library for image resizing. Seems to produce worse quality than the above options in MagicScaler, and still worse than the default resizing with downsizing large images via CSS which doesn't seem to make sense to me.

Second edit: Noticed MagicScaler doesn't work on the Linux box I have things hosted on so also tried a solution in Python. Basically every library I try fails to achieve a sharp, downscaled image that looks as good as MagicScaler, and even that fails to look as good as native in-browser downsizing. Not really sure why any of that would be the case.

Atoramos fucked around with this message at 05:35 on May 7, 2020

Boz0r
Sep 7, 2006
The Rocketship in action.
So the general consensus is that making external calls in a catch block is a really bad idea.

EssOEss
Oct 23, 2006
128-bit approved
A catch statement is just a really elaborate if-else. If your error handling code really needs to do external calls then do them.

Perhaps a better question here would be why does your error handling code need to perform external calls there? And even if the calls are important (e.g. saving error report to database - sure why not) is it really right for these calls to be happening synchronously? Maybe it would be better to instead fire off a task into the thread pool for asynchronous reporting?

NihilCredo posted:

Also, the recovery path for a 4xx error is fundamentally different from the recovery from a connection error.

Sometimes one does not care and the "recovery path" is just:

Atoramos
Aug 31, 2003

Jim's now a Blind Cave Salamander!


Funny enough, the images that break System.Drawing also break SixLabors.ImageSharp, and since I can't use MagicScaler on my linux box I gotta find some other solution. CV2 and Pillow from Python don't produce as nice results.

So far my working solution is a Python executable that runs Pillow to do an in-place re-save of the broken images which lets SixLabors.ImageSharp successfully process them, and then run GaussianSharpen(.6f) on the resulting thumbnail which looks relatively close to the results of MagicScaler (but still not quite as nice as MagicScaler, oh well). Very curious if anyone else has experience with this, especially curious why browsers would provide better results from CSS downsampling (which seems ridiculous to me).

edit: Ahhh can't use a Python executable on Linux either. Not a problem, imported the python script for resaving and launching the script itself seems to be a solution. Still wishing I understood why browser CSS resizing is the end-all be-all for goodlooking downsampling

Atoramos fucked around with this message at 22:54 on May 7, 2020

biznatchio
Mar 31, 2001


Buglord
My philosophy is that as much should go into the catch block as necessary (but no more) to accomplish three goals:

1) Record the failure with enough fidelity to enable postmortem analysis;
2) Any necessary cleanup and rollback for the failure, whether that's done immediately in-line or if you just schedule it for something else; and
3) If for any reason #1 or #2 fail and you're going to surface a new error as a result, it must always be written such that the evidence of the original failure that led to you being in the catch block in the first place is preserved in a way that's discoverable (e.g. InnerException, logging).

For #2, it may very well be that whatever you're protecting has no logic that needs to be executed to compensate for the failure. If your task was to open a file, and you failed to open the file, then there's no cleanup you need to do as a result of that.

But if your task was to open a file, fill it with structured data, flush it and close it, and you failed midway through writing data, then your compensation logic might be complicated, such as deleting the half-written file, copying it somewhere, sending out a service bus message, or whatever other various things you might need to do to prevent that failure from persisting as broken application state. And since compensation logic can fail in its own right, you need to think about what you can do to fail safe when cleanup isn't possible (up to and including stopping the whole drat service if things are severe enough).

My first preference is to treat a try/catch block like a database transaction. Either it succeeds fully, or it backs out and leaves no trace other than the failure being returned or rethrown. But in some cases 'backing out' isn't the right compensation, and 'gracefully transitioning into a known error state' is instead.

biznatchio fucked around with this message at 19:46 on May 7, 2020

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
This is technically an SQL server and Azure question, but I figured this is probably still a good thread for it.

I'll avoid the whole X/Y thing and just tell you guys what I want to do. I want to take a copy of our production database, strip the user accounts, and then replace our dev/test/whatever databases with this copy. This way they'll match up with prod except for the user accounts, which is what we need.

I have the backups, restored locally and with user accounts removed - but how do I actually replace the contents of the existing non-prod databases with these new databases? I'm no DBA, so all of the myriad options in SSMS for exporting/backup/restore/deploy/etc, etc all just look very confusing to me.

Mr Shiny Pants
Nov 12, 2012

a hot gujju bhabhi posted:

This is technically an SQL server and Azure question, but I figured this is probably still a good thread for it.

I'll avoid the whole X/Y thing and just tell you guys what I want to do. I want to take a copy of our production database, strip the user accounts, and then replace our dev/test/whatever databases with this copy. This way they'll match up with prod except for the user accounts, which is what we need.

I have the backups, restored locally and with user accounts removed - but how do I actually replace the contents of the existing non-prod databases with these new databases? I'm no DBA, so all of the myriad options in SSMS for exporting/backup/restore/deploy/etc, etc all just look very confusing to me.

Backup and restore could also work depending on how you setup security.

Import export wizard seems like it might do the trick: https://docs.microsoft.com/en-us/sq...ql-server-ver15

zerofunk
Apr 24, 2004
That would be my first approach too. Just delete the existing non-prod databases and then restore backups of the new ones in their place? Or you might be able to skip deletion and restore over them. I'm not sure if it's the best way to do it and it probably wouldn't work in all use cases. I am also not a DBA.

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

zerofunk posted:

That would be my first approach too. Just delete the existing non-prod databases and then restore backups of the new ones in their place? Or you might be able to skip deletion and restore over them. I'm not sure if it's the best way to do it and it probably wouldn't work in all use cases. I am also not a DBA.

Yeah I'd rather restore over them if possible but the backup/restore options don't show up in SSMS for those Azure hosted DBs. I think it's something to do with the fact that they're managed by Azure.

zerofunk
Apr 24, 2004

a hot gujju bhabhi posted:

Yeah I'd rather restore over them if possible but the backup/restore options don't show up in SSMS for those Azure hosted DBs. I think it's something to do with the fact that they're managed by Azure.

Ahh, yeah I haven't worked with Azure managed ones, so I'm not at all familiar with that. Might still be possible to do it somehow and just not through SSMS itself? Or if you have an older version of SSMS, newer ones might support it.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Am I going mad or have they removed "trim trailing whitespace" from the latest version of visual studio? What a bizarre thing to get rid of

Adbot
ADBOT LOVES YOU

zerofunk
Apr 24, 2004

Hammerite posted:

Am I going mad or have they removed "trim trailing whitespace" from the latest version of visual studio? What a bizarre thing to get rid of

This has been driving me crazy lately because we have it setup so that causes a warning. I used to never have an issue with that and now I'm running into it all the time. I apparently will always add a space after a word even if the last one on that line out of habit. So if I'm writing a multi-line comment, it's guaranteed to have a few warnings that I have to go back and correct.

With VS2017, I had ReSharper setup, but I haven't been using it with VS2019. Kind of assumed that was the difference because there was a period during that transition where I wasn't doing a lot of development in VS, so I'm not really sure.

I also feel like I recently saw a setting for it in the VS options somewhere. I can't find it now though.

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