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
NihilCredo
Jun 6, 2011

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

Jabor posted:

Can you wire up a second log sink that accepts logs at a more verbose level from the paths of interest?

Clever idea, although highly unidiomatic. We have five log sinks right now (console, local file, NewRelic, Slack, email), with Slack and Email already filtering only for critical actionable errors.

I could set a fixed initial log level to Verbose, then the three general sinks (console, local file, NewRelic) could filter by the runtime log level switch, then when a job wants a more detailed log level I can spawn three new clone sinks with a filter looking only for the property identifying the focused job *and* for log levels higher than the global one (to prevent Information+ logs from entering both sinks).

This would definitely do what I want, although 'cleanup' is a problem - log sinks can't really be added at runtime, what you do is replace the existing ILogger with a new one that holds the new sinks and also pipes all the logs to the old ILogger. So to remove temporary sinks, I would need to save a reference to the old ILogger and then put it back in place of the new one. Should be doable, I'll keep this noted as a plan B. Thanks!

zokie posted:

Get rid of the global logger instance, in aspnetcore you can set log levels on namespaces look into doing that but I guess a single global logger instance is going to be a problem.

I had no idea about the per-namespace overriding, Serilog has it too, that's really nice to know and could be useful!

Won't solve this problem though, because I need the same exact method (namespace and all) to have a different log level depending on the caller. Eg. when I save a product there's a Verbose log that records the 'before' and 'after' data models, multiple jobs may be saving products but I want to look only at what one specific job is doing.

Kyte posted:

This is only a vague idea but what about replacing the global with something that hangs off the current synchronization context, and then set up a new context with a new logger for the code path you want to log differently? Async/await should flow the context across invocations (unless you've got everything with ConfigureAwait(false) in which case rip I guess).

Or maybe an async local or thread local depending on whether it's async or not.

These are all hacky, but if you want to avoid a major restructuring it'd at least give you global-like behavior without making it fully global.

Yes, that's the idea I was describing in the post. PushProperty() does "hang off the current synchronization context", I believe it hooks on some magic provided by AsyncLocal<T>, but I need to understand it better.

Adbot
ADBOT LOVES YOU

Red Mike
Jul 11, 2011

Jen heir rick posted:

Just checked this. It is returning a List object whether or not you specify the Buffered option or not. If you do not pass in Buffered=true then upon the second iteration you will get the error: Invalid attempt to call Read when reader was closed. Additionally the query is executed as soon as I call QueryAsync. Not upon iteration. When you iterate it's just calling the data reader methods. I also made sure I'm using the latest version of Dapper.


insta posted:

Check the underlying return type of the object, if you can. Dapper has a Buffered option that will fill a List and give you the List, which can be iterated over repeatedly without a second query, but it's still IMO dangerous in that flipping a boolean somewhere can cause multiple queries to start executing again.

The buffered option defaults to on nowadays, not sure when this changed because it definitely defaulted to off for a very long time. You can explicitly disable it, and it is suggested you do that when you're expecting to read in a very large result set.

zokie
Feb 13, 2006

Out of many, Sweden
As always when we have a problem in programming, we should look at how someone would solve that in functional land.

It’s easy, state is bad, same goes for classes and other OO crap. Pure functions all the way baby!

In more practical terms, keep or get rid of the instance/member/global logger but have the methods that need weird your weird context driven logging take a logger as a parameter. That way the caller can decide what they wanna do with all the logging being done inside.

Purity is really the best

Kyte
Nov 19, 2013

Never quacked for this
He did already consider that but it'd involve refactoring a ton of code to include the new parameter.
And this is not for a specific code path, so it'd need everything refactored.

zokie
Feb 13, 2006

Out of many, Sweden
Make it optional, and it’s the way to solve the problem. A machine can’t just know if something is relevant sometimes, we have to tell them. It’s programming not magic

Boz0r
Sep 7, 2006
The Rocketship in action.
We have an Azure Function that starts an orchestrator function that starts another bunch of functions. I'd like to test all these functions by calling the first one, but I want to mock all outgoing calls. How should I do this? Can I do it in xunit, or should I build something else altogether?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Boz0r posted:

We have an Azure Function that starts an orchestrator function that starts another bunch of functions. I'd like to test all these functions by calling the first one, but I want to mock all outgoing calls. How should I do this? Can I do it in xunit, or should I build something else altogether?

Durable functions are a huge pain in the rear end to test. Generally speaking, you don't end-to-end test like that because an orchestration triggering a sub-orchestration or activity relies on the durable function runtime, period, end-of-story.

You test that the orchestration tells the function runtime to start the appropriate sub-orchestration, and that the sub-orchestrations start the correct activities, then test the activities.

Basically you spend a lot of time creating mocks against IDurableClient or whatever.

Boz0r
Sep 7, 2006
The Rocketship in action.

New Yorp New Yorp posted:

Durable functions are a huge pain in the rear end to test. Generally speaking, you don't end-to-end test like that because an orchestration triggering a sub-orchestration or activity relies on the durable function runtime, period, end-of-story.

You test that the orchestration tells the function runtime to start the appropriate sub-orchestration, and that the sub-orchestrations start the correct activities, then test the activities.

Basically you spend a lot of time creating mocks against IDurableClient or whatever.

I'd really like to, though. How about using that Generic Host builder to start the function host up, mock the outgoing services, and call the http triggered initial function?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Boz0r posted:

I'd really like to, though. How about using that Generic Host builder to start the function host up, mock the outgoing services, and call the http triggered initial function?

That would probably get you as far as being able to test the logic contained in the trigger function. But without having a full running instance of the function runtime, you're not going to be able to integration test beyond the orchestration boundaries. Last time I did any significant durable function work, I spent a lot of time mocking CallActivity/StartOrchestration/etc and validating that they were called the correct number of times with the correct data. It sucked.

Boz0r
Sep 7, 2006
The Rocketship in action.

New Yorp New Yorp posted:

That would probably get you as far as being able to test the logic contained in the trigger function. But without having a full running instance of the function runtime, you're not going to be able to integration test beyond the orchestration boundaries. Last time I did any significant durable function work, I spent a lot of time mocking CallActivity/StartOrchestration/etc and validating that they were called the correct number of times with the correct data. It sucked.

drat, that sucks. Is this kind of end-to-end testing uncommon? Or is missing support for it in Azure Functions an oversight on Microsoft's part?

EDIT: I assume there's no in-memory variant of Azure Storage I can use.

Boz0r fucked around with this message at 09:57 on Mar 29, 2022

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Boz0r posted:

drat, that sucks. Is this kind of end-to-end testing uncommon? Or is missing support for it in Azure Functions an oversight on Microsoft's part?

EDIT: I assume there's no in-memory variant of Azure Storage I can use.

I don't know if it's common or not, it's just difficult. Part of it is just the nature of durable functions: The entire idea is that you're creating a bunch of stateless, deterministic orchestrations and then passing it off to the functions runtime to schedule, execute, and provide results. You want as little logic as possible in your orchestrations and nice, unit testable activities.

You can certainly E2E test it if you start up an instance with the func CLI and then test only through HTTP triggers, but the function's inner workings are going to be opaque: Put a message into the box, machinery grinds away at it, you get a result. Last time I did a reasonably sized durable functions project, I didn't bother -- I just unit tested the hell out of all of my orchestrations and activities until I had a reasonable level of confidence that the right orchestrations and activities were firing given the right circumstances.

There's the Azure Storage Emulator, which is what runs when you debug a function app locally. That's about as good as it gets.

LongSack
Jan 17, 2003

New Yorp New Yorp posted:

There's the Azure Storage Emulator, which is what runs when you debug a function app locally. That's about as good as it gets.

Azure storage emulator is deprecated in favor of something called Azurite. In my last project, for testing, I could not figure out how to get Azurite to start automatically, I had to start it manually.

Reference

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
I am currently having to interact with an Active Directory server via LDAP, using LdapConnection; part of what I need to do involves retrieving user properties (e.g. the `memberOf` attribute). This, and other properties, are returning as an array of ascii values; I would like them to be in a more human readable form (e.g. like what ldp.exe returns). I think that ldp is just doing some intelligent decoding behind the scenes, and I'm wondering if LdapConnection has the same capabilities via some configuration option I'm just missing.

Failing that, is there a way of determining ahead of time what attributes are going to be returned as ascii? I realize this might not be the best place for this question, so if there's somewhere else I should ask I'd love to hear about it

fuf
Sep 12, 2004

haha
I'm trying to test a .net app using my phone so I want to access it via the local network.

I added this to launchSettings.json:
"applicationUrl": "http://0.0.0.0:5001",

and it works for accessing the app via http://192.168.0.24:5001/ but it doesn't work with https.

Is there a way to get https working? I read something about https not working with IP addresses because it needs a domain name? Do I need to give my development PC a domain name on the local network somehow?

Red Mike
Jul 11, 2011

fuf posted:

I'm trying to test a .net app using my phone so I want to access it via the local network.

I added this to launchSettings.json:
"applicationUrl": "http://0.0.0.0:5001",

and it works for accessing the app via http://192.168.0.24:5001/ but it doesn't work with https.

Is there a way to get https working? I read something about https not working with IP addresses because it needs a domain name? Do I need to give my development PC a domain name on the local network somehow?

An IP address is fine, so long as you set up your phone to accept the self-signed certificate it'll be using. Assuming you're on Android, follow a guide like this. I believe iOS has a much weirder/worse process, but I haven't had to go through that recently.

Just-In-Timeberlake
Aug 18, 2003

fuf posted:

I'm trying to test a .net app using my phone so I want to access it via the local network.

I added this to launchSettings.json:
"applicationUrl": "http://0.0.0.0:5001",

and it works for accessing the app via http://192.168.0.24:5001/ but it doesn't work with https.

Is there a way to get https working? I read something about https not working with IP addresses because it needs a domain name? Do I need to give my development PC a domain name on the local network somehow?

Doesn't the HTTPS endpoint need to be on a different port? In ASP.NET in the applicationhost.config you need something like this:

code:
<bindings>
	<binding protocol="http" bindingInformation="*:3778:localhost" />
        <binding protocol="https" bindingInformation="*:44345:localhost" />
</bindings>

fuf
Sep 12, 2004

haha
I can't actually get the self-signed cert to work on anything other than localhost, even just accessing from my dev machine

my launchSettings.json looks like this:

code:
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:61949",
      "sslPort": 44393
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyProject": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://0.0.0.0:5001",
      "dotnetRunMessages": true,
      "sslPort": 44393
    }
  }
}
If I launch with the IIS Express profile then I can access the app at https://localhost:44393 and Chrome is happy

If I launch with the MyProject profile then I can still access the app at https://192.168.0.24:44393 but I get a "Not Secure" warning in Chrome and have to do the "proceed anyway" thing.

I tried running
"dotnet dev-certs https"
But it gives
"A valid HTTPS certificate is already present."

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick

fuf posted:

If I launch with the MyProject profile then I can still access the app at https://192.168.0.24:44393 but I get a "Not Secure" warning in Chrome and have to do the "proceed anyway" thing.

I tried running
"dotnet dev-certs https"
But it gives
"A valid HTTPS certificate is already present."

That’s because the cert is issued to the domain localhost, not to 192.168.0.24.

NihilCredo
Jun 6, 2011

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

Not really what you asked, but nowadays I prefer to use Ngrok when testing a web service running on my machine. Way easier than fiddling with local network security and hacky SSL certs.

Sab669
Sep 24, 2009

Does Visual Studio 2019 have a "use Windows theme" functionality like VSC does?



It'd be nice to have all my IDEs swap between Light & Dark with the swap of the Windows setting. But I can't seem to find it :(

Toast Museum
Dec 3, 2005

30% Iron Chef

Sab669 posted:

Does Visual Studio 2019 have a "use Windows theme" functionality like VSC does?



It'd be nice to have all my IDEs swap between Light & Dark with the swap of the Windows setting. But I can't seem to find it :(

If upgrading is an option, that feature was added for Visual Studio 2022. There are a couple of 2019 extensions that seem to add this feature, but I can't vouch for them.

LongSack
Jan 17, 2003

I'm rewriting one of my apps from Blazor Server to React with an ASP.Net Core 6 API backend using minimal apis.

I notice that the kestrel console shows one "405 HTTP Method Not Supported" for every successful request, for example:
code:
Endpoint: 405 HTTP Method Not Supported
Endpoint: HTTP: GET /api/v1/User/ByEmail/{email} => ByEmail
Endpoint: 405 HTTP Method Not Supported
Endpoint: HTTP: GET /api/v1/Category => GetCategories
Endpoint: 405 HTTP Method Not Supported
Endpoint: HTTP: GET /api/v1/Category => GetCategories
This 405 status does not show up in the dev tools network tab, instead there's a "preflight" OPTIONS request that show a 204 response.

I don't know whether this 405 is being triggered by the OPTIONS request (but then if so, why does the browser show a 204?) or by something else.

I don't recall getting these statuses in the original version of the app, but that was using traditional controllers and a Blazor Server front end.

It's not effecting the application's function, but it's irritating and I worry that it might be effecting the app performance.

Any ideas? TIA

NihilCredo
Jun 6, 2011

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

No clue but I would start by raising the log level. It should show the original request and path, at the very least.

LongSack
Jan 17, 2003

NihilCredo posted:

No clue but I would start by raising the log level. It should show the original request and path, at the very least.

Good thinking. The 405 IS being logged during the preflight "OPTIONS" request:
code:
      Request starting HTTP/2 OPTIONS https://localhost:5011/api/v1/User/ByEmail/user@my.email - -
dbug: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
      Wildcard detected, all requests with hosts will be allowed.
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
      1 candidate(s) found for the request path '/api/v1/User/ByEmail/user@my.email'
dbug: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[1]
      Request matched endpoint '405 HTTP Method Not Supported'
dbug: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[15]
      Static files was skipped as the request already matched an endpoint.
Endpoint: 405 HTTP Method Not Supported
dbug: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[2]
      The request has an origin header: 'http://localhost:3000'.
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
      CORS policy execution successful.
dbug: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[1]
      The request is a preflight request.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 OPTIONS https://localhost:5011/api/v1/User/ByEmail/user@my.email - - - 204 - - 61.9603ms
and it is responding with a 204 to the request. Beyond that, it's not very helpful.

This does not appear to be a legitimate 405 error, since the OPTIONS request is being processed and a 204 is returned. I found one google hit that appeared relevant, and it was related to ASP.NET Core Identity (which I'm not using, I don't think - I'm authenticating with Auth0 and using JWT Bearer tokens).

Kyte
Nov 19, 2013

Never quacked for this
There seem to be two actors involved here. The request is sent to EndpointRoutingMiddleware, which matches it to the 405 Method Not Allowed endpoint. However, midstream during the response processing, the CorsService evaluates the request/response, recognizes it as a preflight, and modifies the response appropriately.

Perhaps if you set up your own endpoint for OPTIONS it'd shut the message up. Supposing CorsService continues to intercept the request/response, the clientside result should be the same.
(Or maybe a middleware? I'm not sure where does CorsService sit in the request pipeline)

Kyte fucked around with this message at 17:33 on Apr 27, 2022

LongSack
Jan 17, 2003

Kyte posted:

There seem to be two actors involved here. The request is sent to EndpointRoutingMiddleware, which matches it to the 405 Method Not Allowed endpoint. However, midstream during the response processing, the CorsService evaluates the request/response, recognizes it as a preflight, and modifies the response appropriately.

Yes, I poked around in the source code a bit and I think this is exactly what's happening. The 405 endpoint is being selected (and logged) because there is no OPTIONS endpoint, but then the CORS middleware short-circuits the pipeline. IMO it shouldn't be logging the 405 endpoint to the console (or else it is doing it too early), but I don't think it is actually effecting anything so I'm going to ignore it.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
https://stackoverflow.com/questions/36470091/unsubscribe-then-subscribe-to-console-cancelkeypress

Spent like an hour and a half Getting Angry With The Computer today because of this.

zokie
Feb 13, 2006

Out of many, Sweden
I have to make a GUI application and distribute it internally. It looks like I can choose from WinUI 2, WinUI 3, WPF, and WinForms. I’ve used both WinForms and WPF before (5+ years ago). But what I care about the most except for easy installation and updates (ClickOnce looks like it’s still around) I would really like to make the application window me an exotic shape.

Anyone knows if that can be done?

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with



Grimey Drawer

zokie posted:

I have to make a GUI application and distribute it internally. It looks like I can choose from WinUI 2, WinUI 3, WPF, and WinForms. I’ve used both WinForms and WPF before (5+ years ago). But what I care about the most except for easy installation and updates (ClickOnce looks like it’s still around) I would really like to make the application window me an exotic shape.

Anyone knows if that can be done?

So you can do this, but I kinda recommend against it, depending on what you mean by 'exotic'.

Fundamentally, your window is going to be a box no matter how you spin it, but you can make portions of it transparent and click through and all that if you want and craft a shape however you please. The real problems start in window manipulation. Depending on your shape, resizing might not be very intuitive, or even possible. You have to make sure you are building it correctly to make it resize without problems like distortion or weird margin problems. You probably will need to build your own resizing handles (although maybe chrome lets you set offsets and positions?). You end up with a lot of goofy considerations. You'll have to override the default Title Bar(which is not hard, but another thing to do).

Regardless, write it in WPF. WinUI loving sucks compared to WPF dont @ me. If you are writing your logic in C++ though, it's probably fine.

Canine Blues Arooo fucked around with this message at 00:44 on Apr 29, 2022

brap
Aug 23, 2004

Grimey Drawer
write it in MAUI :hehe:

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
WinUI2 is UWP, don't bother

WPF is, more or less, on life support. It's one of those things that only gets features when someone goes "Crap, we really need X!" and then vendors are hired to do X, then it stays static again.

WinForms has been around the longest and gets features built for it, although they are small ones. IMO it's pretty safe. Although I don't like the general architecture of how apps are constructed generally with it, I'm not a fan of the designer. YMMV.

WinUI3, honestly, isn't that bad to me. Especially with the Unpackaged mode (where it's a raw EXE) and how loose the restrictions are on what it can access. It has fewer ready-built libraries than WPF / WinForms since it's so new, and it's maintained by the Windows team so YMMV on how long it will last in this form.

MAUI is hell.

Drastic Actions fucked around with this message at 00:49 on Apr 29, 2022

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with



Grimey Drawer
My favorite MS selling point of WinUI3 is that 'you can create modern looking apps'. That's a style preset my dude.

Please just maintain WPF as your native win32 framework until you actually have a good reason not to. Stop with this 'new framework' nonsense.


These are facts.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
So funny thing about MAUI: As some of you know, MAUI stands for ".NET Multi-platform App UI." As the Xamarin name is slowly sunset, there needs to be a name for the SDKs (Xamarin.iOS, Xamarin.Mac, Xamarin.Android, etc.)

It was decided that these SDKs would also be called "MAUI." So when you build a .NET 6 app that is running on, say, iOS, that will also be called "MAUI."

Some of you may be saying "Wait DA, I thought MAUI was the next version of Xamarin.Forms?" and yes, it is.

"So if I build a .NET 6 iOS app, that doesn't use the cross-platform UI framework of MAUI, it's still a MAUI app?"

It is. And no, I got no idea why or how that makes sense.

mystes
May 31, 2006

Avalon is starting to look decent.

GI_Clutch
Aug 22, 2000

by Fluffdaddy
Dinosaur Gum
Every once in a while I want to take another stab at WPF and do it properly with MVVM. Then I build a test app and remember why I gave up the last time. Even in .NET 6, WPF does not play nice with G-Sync monitors (and other adaptive sync monitors, I believe) if you have G-Sync enabled for windowed and full screen apps. I watch as my mouse stutters across the screen when my app has focus and say gently caress it and just make something with winforms. Yeah, I can set up a profile for the individual application to not use G-Sync, but ain't no one got time for that.

They're usually just quick little utilities to make my life or a co-worker's life easier anyway, so I'm not too concerned that my basic typically one or two form application is mixing my business logic with my UI logic. Though I did make a couple projects using that MVP pattern and that worked out well enough.

Just-In-Timeberlake
Aug 18, 2003

zokie posted:

I would really like to make the application window me an exotic shape.


There are easier ways to make Winamp skins

zokie
Feb 13, 2006

Out of many, Sweden
Thanks for all the replies, the reason for the window shape is that our team has a mascot and the application is just going to be a gui for a file watcher for people we don’t expect being able to handle a cli so I wanted to do something fun while developing it.

Toast Museum
Dec 3, 2005

30% Iron Chef
What's best practice for building an XPath query in C#? I'm querying event logs, and I'd like to give myself some options with the search criteria. I'm assuming there's a better approach than just concatenating strings containing chunks of the query, but I haven't found it yet.

NihilCredo
Jun 6, 2011

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

Toast Museum posted:

What's best practice for building an XPath query in C#? I'm querying event logs, and I'd like to give myself some options with the search criteria. I'm assuming there's a better approach than just concatenating strings containing chunks of the query, but I haven't found it yet.

Sounds like you want System.Xml.XPath.XPathNavigator?

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Visual Studio on my work machine is frequently getting itself into a state where it doesn't acknowledge certain keyboard inputs. It accepts printable characters, but it won't react to (for example) the enter key, the delete or backspace key, function keys, or combinations of meta and regular keys. The only way to fix it is to close and reopen VS. Anyone else had this?

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