|
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?
|
# ? Apr 29, 2020 14:11 |
|
|
# ? May 18, 2024 05:45 |
|
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.
|
# ? Apr 29, 2020 14:32 |
|
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.
|
# ? Apr 29, 2020 18:19 |
|
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.
|
# ? Apr 29, 2020 19:36 |
|
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:
C# code:
C# code:
In VS Code however, all I've found through Googling is some advice to use this editor config: code:
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:
putin is a cunt fucked around with this message at 23:29 on Apr 29, 2020 |
# ? Apr 29, 2020 23:25 |
|
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.
|
# ? Apr 30, 2020 03:30 |
|
namlosh posted:Did log4net fall out of favor? That’s what we use, but we just write to disk and the windows event log. 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.
|
# ? Apr 30, 2020 05:34 |
|
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.)
|
# ? Apr 30, 2020 05:50 |
|
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.
|
# ? Apr 30, 2020 06:03 |
|
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! 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!
|
# ? Apr 30, 2020 06:37 |
|
Rocko Bonaparte posted:Wow that's a hell of a thing to do on April 1st. Are all the cool kids using something else? 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 |
# ? Apr 30, 2020 08:16 |
|
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.
|
# ? May 1, 2020 00:26 |
|
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.
|
# ? May 2, 2020 16:55 |
|
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.
|
# ? May 2, 2020 18:30 |
|
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.
|
# ? May 6, 2020 08:17 |
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.)
|
|
# ? May 6, 2020 09:21 |
|
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.
|
# ? May 6, 2020 14:14 |
|
Had a nice bug the other day where an Exception class constructor was calling an external service (and the call was failing).
|
# ? May 6, 2020 16:20 |
|
Eggnogium posted:Had a nice bug the other day where an Exception class constructor was calling an external service (and the call was failing).
|
# ? May 6, 2020 17:45 |
|
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.)
|
# ? May 6, 2020 18:30 |
|
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:
|
# ? May 6, 2020 18:38 |
|
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:
|
# ? May 6, 2020 19:20 |
|
NihilCredo posted:Twelve years later and this essay is still my Bible when it comes to writing error-handling code. Ah this owns, very nice
|
# ? May 6, 2020 19:35 |
|
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?”
|
# ? May 6, 2020 19:57 |
|
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.
|
# ? May 6, 2020 20:19 |
|
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.
|
# ? May 6, 2020 20:21 |
|
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
|
# ? May 6, 2020 20:26 |
|
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.
|
# ? May 6, 2020 21:02 |
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:
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 |
|
# ? May 6, 2020 22:23 |
|
So the general consensus is that making external calls in a catch block is a really bad idea.
|
# ? May 7, 2020 11:21 |
|
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:
|
# ? May 7, 2020 11:41 |
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 |
|
# ? May 7, 2020 19:21 |
|
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 |
# ? May 7, 2020 19:44 |
|
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.
|
# ? May 8, 2020 07:24 |
|
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. 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
|
# ? May 8, 2020 07:30 |
|
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.
|
# ? May 8, 2020 08:09 |
|
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.
|
# ? May 8, 2020 09:27 |
|
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.
|
# ? May 8, 2020 10:07 |
|
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
|
# ? May 13, 2020 16:31 |
|
|
# ? May 18, 2024 05:45 |
|
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.
|
# ? May 13, 2020 21:06 |