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
CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Anyone have any experience with using PushSharp to send push notifications? I switched to that from JdSoft because JdSoft stopped working entirely, hadn't been updated in forever, and was only for iOS devices anyway.

So anyway I switched to PushSharp, and set it up, and my test messages to my phone worked, but I've hit a problem. When I try to send notifications to multiple phones at once, the whole thing gets incredibly unreliable -- whether or not the notifications go out at all seems basically random, and more get dropped than get through. I'm doing this:
code:
AppleNotification notification;
foreach (device dev in devices.Where(x => x.send_notifications == 1).ToList())
{
	try
	{
		notification = new AppleNotification()
				   .ForDeviceToken(dev.device_key)
				   .WithAlert("Hello World!")
				   .WithBadge(0)
				   .WithSound("sound.caf");
		push.QueueNotification(notification);
	}
	catch { }
}
That try/catch there is me thinking "well, maybe one of the device keys are bad or something and if I isolate it, the rest will go out?", but that didn't work. I'm using the same AppleNotification over and over again because I saw some object disposed exceptions and thought maybe the loop didn't like me doing QueueNotification(new AppleNotification etc. etc.) again and again, but again, still unreliable.

Because it might matter: push is a PushBroker that I instantiated and did RegisterAppleServices on Form_Load, the push notifications get sent by a function call. Maybe that's the problem? Creating a new PushBroker for each notification doesn't sound right, but who knows.

The google results I've found have mostly been about generating the certificate or something. This looks really close, but I'm not sending GcmNotifications and can't find an AddRange thing in AppleNotifications.

edit: This works:
code:
AppleNotification notification;
foreach (device dev in devices.Where(x => x.send_notifications == 1).ToList())
{
	try
	{
		push = new PushBroker();
		push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "123456")); 

		notification = new AppleNotification()
				   .ForDeviceToken(dev.device_key)
				   .WithAlert("Hello World!")
				   .WithBadge(0)
				   .WithSound("sound.caf");
		push.QueueNotification(notification);
	}
	catch { }
}
That can't seriously be the right way to do it, though, can it?

Also yes the password to my push certificate is 123456, please don't tell any hackers.

CapnAndy fucked around with this message at 23:41 on Dec 10, 2014

Adbot
ADBOT LOVES YOU

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I've discovered some code left by my predecessor that's just baffling to me; can anyone shed some light? Basically, I've got a program that, when it sees it's time for an update, closes itself and calls SelfUpdate.exe, which is in the same folder. SelfUpdate.exe goes and fetches the new files and extracts them. All that makes sense. And then I hit this:
code:
string[] args = Environment.GetCommandLineArgs();
get_file("Main file", args[1]);
Application.DoEvents();

System.Diagnostics.Process.Start(args[1]);
So he's obviously using the second command line argument to get the path of the original file. What I don't get is why. First off, why is he so sure that the second command line argument is always going to be the path of the file that called SelfUpdate? It clearly is -- this process works -- but this seems like a hell of a thing to grab blindly like that. Secondly, why's he doing this at all? SelfUpdate knows goddamn well where the original file is because they're in the same folder as each other, it is not hard to locate. My reaction is "this is bad code, rewrite it", but it's so outside anything I've seen before that I want to double-check that he's not actually being brilliant.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
He does pass the program the path, but the URL it downloads from is hardcoded.

ljw1004 posted:

I assume that he wrote a general-purpose "SelfUpdate.exe" program which can be used to update any executable. As long as it's passed the URL to download from, and the name of the EXE, then it should be agnostic (i.e. loosely coupled) to the calling program.
This is probably the truth anyway, I've uncovered the ruins of a couple other things that were clearly meant to be big deals but never got implemented and just stuck around as confusing code snippets prone to breaking stuff. Thanks.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
So today I learned that HttpWebResponse throws an error on 404 and you have to wrap the whole thing in try/catch and you can use the exception's response code in the catch segment.

CHECKING TO SEE IF THE WEBSITE IS THERE IS EXACTLY WHAT I'M USING YOU FOR, YOU STUPID CALL, WHY DO YOU NOT KNOW HOW TO HANDLE loving 404S


I just needed to vent.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Lone_Strider posted:

It also throws an exception on 304 Not Modified! I hated seeing "The remote server returned an error: 304 (Not Modified)" because the server wasn't in the wrong :argh: If you have the option, using HttpClient in System.Net.Http (.NET 4.5 I think?) is much better.
3.5, so I don't have the option.

If the exception has a recognizable response code why are you throwing exceptions, you know exactly what those responses are you stupid call.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Okay, this is baffling and if Google is any indication, has happened to literally nobody ever, so who wants a brainteaser?

I've got a WPF application that needs to read card swipes, which come in as keystrokes from the reader so it's pretty easy. In the application's constructor, I have this line:
code:
TextCompositionManager.AddPreviewTextInputStartHandler(this, new TextCompositionEventHandler(tcphandler));
Which leads to this function:
code:
public void tcphandler(object o, TextCompositionEventArgs e)
{
	e.Handled = true;
	cardbuffer += e.Text;
}
The e.Handled is there so the keystrokes don't go any further, and then I have OnKeyDown events to actually read the cardbuffer and decide when a card is finished being swiped. All of this works.

However, if you click anything on a page that takes any sort of interaction (buttons and textboxes are the two things I've found so far), the code stops working -- but only for the space bar. Every other keystroke still gets caught just fine, but space bar presses simply do not trigger tcphandler at all. I know they're going through because they trigger OnKeyDown just fine (and show up in the text box, because tcphandler isn't stopping them). There is absolutely zero code anywhere in the project regarding space bars being pressed.

Once you click away from the button or textbox, space bars still are not caught. However, loading a new page causes spaces to be properly handled again, until and unless you click a button or textbox, at which point they start failing to be caught again and can only be fixed by loading a new page.

CapnAndy fucked around with this message at 01:33 on May 18, 2016

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

IcedPee posted:

Does anyone have a link to a good article about how events propagate from a timer? I have this timer

code:

 public void StartTimer()
        {
            //Set timer for one second
            _timer = new Timer(1000);
            _timeLeft = 10;
            _timer.Elapsed += Timer_Elapsed;

            _timer.Start();

        }

private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (_timeLeft >= 1 && !_stopTimer)
            {
                //Take it down and restart the one second timer
                _timeLeft--;
                
            }
            else
            {                
                _timer.Stop();
                OnTimerEnded(new EventArgs());
            }
        }

In addition, I've also got this event that could happen as a result from touch input

code:

 public override bool OnTouchEvent(MotionEvent e)
        {
            base.OnTouchEvent(e);
            if (e.Action == MotionEventActions.Down)
            {
                prevx = e.GetX();
                prevy = e.GetY();
            }
            if (e.Action == MotionEventActions.Move)
            {
                float e_x = e.GetX();
                float e_y = e.GetY();

                xdiff = (prevx - e_x);
                ydiff = (prevy - e_y);
                xangle = xangle + ydiff;
                yangle = yangle + xdiff;

                //add to the total distance
                totalDistance += Math.Abs(xdiff);
                totalDistance += Math.Abs(ydiff);

                if(totalDistance >= 400)
                {
                    totalDistance = 0;
                    ThingEvent?.Invoke(this, new ThingEventArgs());
                }

                prevx = e_x;
                prevy = e_y;
            }
            
            return true;
        }


protected virtual void OnThingEvent(object sender,ThingEventArgs e)
        {
            
            _stopTimer = true;
            
        }

Well, long story short, OnThingEvent fires predictably and sets _stopTimer to true, but Timer_Elapsed will continue to run and when the 10 seconds have counted down, _stopTimer is false. Nowhere else is _stopTimer accessed. I know this has to be a threading issue, I just wanted to know why this occurs and how to fix it.
I don't have an answer for you, but I have a way to get what you want. First off, you're doing Timer_Elapsed when you've got the definition of a ticking timer. Change it to:
code:
_timer = new Timer();
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += new EventHandler(_timer_Tick);
Now you can kill _stopTimer altogether, move the "decrement time left and stop timer if it's 0" logic to _timer_Tick, and just have OnThingEvent call _timer.Stop(), which will immediately stop the ticking. Easy peasy.

CapnAndy fucked around with this message at 17:28 on May 18, 2016

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

IcedPee posted:

Yeah, there's a reason I wasn't doing _timer.Tick - System.Timers.Timer doesn't have a Tick event. I actually create my own tick event and handle it elsewhere for UI stuff. Oddly enough, I have tried calling _timer.Stop() within OnThingEvent, but it doesn't stop the timer when I call it there just like _stopTimer is always reads false in the Timer_Elapsed handler even though I have set it to true in OnThingEvent. I was really hoping that marking _stopTimer as volatile was the solution.

I could try using a winforms timer, but this is a xamarin android application and I think there was a reason that would be bad. I don't recall what it is at the moment, so I'll give it a try.
Does Xamarin have System.Windows.Threading? Threading timers can tick.

If that's still impossible and the problem has to be solved, where do you declare _stopTimer to be false? You've got to be resetting it to false when the timer starts, but you didn't include that bit, or the bit where Timer_Elapsed actually restarts the timer. Without seeing them, I'm going to guess that what's happening is your timer restart method sets _stopTimer to false, and thus even though OnThingEvent sets it true, it gets overriden on the next "tick".

Can you just not call _timer.Stop() from OnThingEvent? I'm not sure if stopping counts as being elapsed, but I don't think it would. And if all of that stuff doesn't work, what about just setting _timeLeft to 0 and letting the regular logic stop itself?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

IcedPee posted:

Currently, I don't think I do set _stopTimer to false anywhere but when it's declared. My focus has been on getting the ThingEvent to successfully stop the timer before I worry about reset logic. StartTimer is called from a button press in the UI and is not used anywhere else in the application.

If setting _stopTimer to true in OnThingEvent handler doesn't change the value that's seen for _stopTimer in Timer_Elapsed, I have serious doubts that changing _timeLeft in the OnThingEvent handler will change the value that's seen for _timeLeft in Timer_Elapsed. I have definitely tried calling _timer.Stop() in OnThingEvent to no avail. This is what leads me to believe this is a threading problem.
I dunno, try it. The timer does time out after 10 seconds, right? You've tested that? Because this almost sounds like Xamarin is giving the timer variables of its very own when it's created.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
My last idea is to declare them static instead of volatile.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Anyone good with with web APIs that require POST requests to be called? It turns out I've literally never done this and I don't even know what the right questions are to ask, so I'm finding everything super confusing. This is the documentation I have, with the actual data removed and replaced with <name of data>:
code:
<URL>
Headers:
accessKey: <accessKey>
version:v2
Post Parameters:
format:xml
listID:<listID>
SubscribersData:
XML Body: 
<SUBSCRIBERINFO>
    <SUBSCRIBER>
        <FIRSTNAME>Joe</FIRSTNAME>
         <LASTNAME>Smith</LASTNAME>
        <CELLPHONENUMBER>18184459595</CELLPHONENUMBER>
        <REFERENCEID>abc78290</REFERENCEID> 
    </SUBSCRIBER>
</SUBSCRIBERINFO>
And I've written this so far:
code:
WebRequest request = WebRequest.Create("<URL>");
request.Method = "POST";
request.Headers.Add("accessKey:<accessKey>");
request.Headers.Add("version:v2");

Stream requestStream;
byte[] parameterStream;
parameterStream = Encoding.UTF8.GetBytes("listID:<listID>");
requestStream = request.GetRequestStream();
requestStream.Write(parameterStream, 0, parameterStream.Length);
requestStream.Close();

WebResponse response = request.GetResponse();
string rs;
using (Stream stream = response.GetResponseStream())
{
	StreamReader reader = new StreamReader(stream, Encoding.UTF8);
	rs = reader.ReadToEnd();
}

rs = request.ToString();
The response is complaining at me that I didn't give it a listID, so I seem to be screwing up in providing the post parameters (and yeah, I know I'm not giving it the format or SubscribersData parametes, I wanted to get one parameter working so I knew I was doing it right), but I copied that from StackOverflow and I don't know why it didn't work. This seems like something that ought to be obnoxiously basic, but, like... why isn't there a request.Parameters I can add to like I did with headers? What am I doing wrong?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I'm working on a WPF project and I'm just stacking up templates that are drat near identical to each other except for one thing. Look at this:
code:
<ControlTemplate x:Key="btn_menu" TargetType="{x:Type Button}">
	<Grid x:Name="grd" Background="#000000" Height="100">
		<TextBlock x:Name="txt_content" Text="{TemplateBinding Content}" 
		Style="{StaticResource txt_menu}" HorizontalAlignment="Center"
 		VerticalAlignment="Center"/>
	</Grid>
	<ControlTemplate.Triggers>
		<Trigger Property="Button.IsPressed" Value="True">
			<Setter TargetName="grd" Property="Background" Value="#E5212D" />
		</Trigger>
	</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="btn_menu_red" TargetType="{x:Type Button}">
	<Grid x:Name="grd" Background="#E5212D" Height="100">
		<TextBlock x:Name="txt_content" Text="{TemplateBinding Content}" 
		Style="{StaticResource txt_menu}" HorizontalAlignment="Center" 
		VerticalAlignment="Center"/>
	</Grid>
	<ControlTemplate.Triggers>
		<Trigger Property="Button.IsPressed" Value="True">
			<Setter TargetName="grd" Property="Background" Value="#000000" />
		</Trigger>
	</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="btn_menu_border" TargetType="{x:Type Button}">
	<Grid x:Name="grd" Background="#000000" Height="100">
		<TextBlock x:Name="txt_content" Text="{TemplateBinding Content}" 
		Style="{StaticResource txt_menu}" HorizontalAlignment="Center" 
		VerticalAlignment="Center"/>
		<Canvas Width="1" Height="60" Background="#4A4040" HorizontalAlignment="Left"
 		VerticalAlignment="Center"/>
	</Grid>
	<ControlTemplate.Triggers>
		<Trigger Property="Button.IsPressed" Value="True">
			<Setter TargetName="grd" Property="Background" Value="#E5212D" />
		</Trigger>
	</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="btn_menu_selected" TargetType="{x:Type Button}">
	<Grid x:Name="grd" Background="#000000" Height="100">
		<TextBlock x:Name="txt_content" Text="{TemplateBinding Content}" 
		Style="{StaticResource txt_menu_red}" HorizontalAlignment="Center" 
		VerticalAlignment="Center"/>
	</Grid>
</ControlTemplate>
I'm driving myself crazy. Is there some cute trick I don't know where I can make, like, whatever the WPF template version of an interface is, and then just make a bunch of templates that just pass in variables for text style, background color, and is there a border yes/no? (And yes, I'm using all of these multiple times, so there's a reason to actually make templates in the first place.)

CapnAndy fucked around with this message at 18:53 on Oct 21, 2016

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
So LINQ to SQL can handle DateTime.AddHours just fine, but only AddHours I guess, because it throws errors on AddMinutes? I mean, fine, it's a one-line workaround. But what the gently caress? Why so oddly specific on only allowing AddHours?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Can someone explain the stupid "type or namespace name 'ProfileCommon' could not be found" error to me? StackOverflow's answers are all exceptionally smug even by their standards and full of dead links that would have supposedly explained what's going on. All I know is I made a Web Application in VS2017 (because web site isn't a frigging option any more), and if I copy the raw files to the web server it works, but if I publish it first I get that dumb error.

What's it bitching about and what do I need to stick in where to make it shut up?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Scaramouche posted:

You've probably read this then but it seems pretty straightforward:
https://stackoverflow.com/questions/11073973/the-type-or-namespace-name-profilecommon-could-not-be-found

Basically the default project creates a config profile out of the box that doesn't get deployed to server as part of publish. The guys in the question above add some Using directives and the last one just stubs out the class so it doesn't complain about it.
I have, yeah. I did try adding the Using directives but it's not like he said where, so I stuck 'em on Global.asax and they did nothing. But that's to be expected, I'd think, they're just empty Using directives, I'm not actually using that stuff. That stub solution did work, though! I didn't try it because it had 0 votes and no comments.

I still don't love that apparently that was straightforward to you, though, because it kept making my eyes cross and that means I've got a gap in my knowledge somewhere.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Did Office 2019 Excel files get a new OLEDB connection string, by some esoteric chance? I've got perfectly good .xlsx files that aren't corrupted or anything -- they'll open in Excel -- but both Microsoft.ACE.OLEDB.12.0 and Microsoft.Jet.OLEDB.4.0 (I tried it just in case) are giving me the same Not In Expected Format errors. The same code will process other Excel files just fine and the department generating the ones that are failing have no idea what version of Excel they use or what could possibly be different about them, and I can't find any other connection strings on Google, but I'm utterly out of ideas and Not In Expected Format gives me dick-all to go off of.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I asked this in General Programming because I thought it was too minor for this thread, but nobody answered, so I guess the .NET specificity of it put people off? So trying it here:

I do not know much about nuget; I have some nuget packages another guy did and I've been able to piggyback off his work enough to keep them updated. But now I have a problem I can't figure out. The .nuspec file has code like this:
code:
<Target Name="Compile" AfterTargets="Compile">
	<Exec Condition="Exists('$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)')" 
	Command="&quot;$(SolutionDir)packages\$(PackageDir)\program.exe do stuff" />
</Target>
Which has been fine until now because we've only used it for .NET Framework stuff. But when I installed it on a .NET Core project, it failed with File Not Found errors, because nuget doesn't install to SolutionDir\packages\PackageDir, it installs to UserDir\.nuget\packages\PackageDir.

Is there a solution to this besides just making two nuget solutions, one for Framework and one for Core? Some way to detect framework and execute a command with the appropriate location string?

Also, since nobody gave me any better solutions I've been working on a separate nuget for Core, but as it turns out I have no idea how to target UserDir in that command language -- %USERPROFILE% doesn't work. Anyone know how to do that? I just want to put this stupid bug to bed, it's got to be a solved problem, there are plenty of NuGet packages targeting Core.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

EssOEss posted:

This is in the csproj file? I would expect $(UserProfile) to work if I remember my MSBuild right.
This is in the .targets file, which to my -- super, super limited and all self-taught from reading this existing thing -- knowledge, is basically a bunch of macros?

edit: but it looks like $(UserProfile) is working!

CapnAndy fucked around with this message at 23:52 on Apr 22, 2020

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I've got a brain teaser here and I could use some extra ideas. I need to connect to an API run by a third party. To do that, I'm using this code:
code:
string url = apiURL;

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(String.Format("{0}{1}", url, ""));
request.ContentType = "application/json";

string APIkey = APIkey;
string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(APIkey));
request.Headers["Authorization"] = "Basic " + authInfo;

using (StreamReader stream = new StreamReader(request.GetResponse().GetResponseStream()))
{
	string response = stream.ReadToEnd();
	stream.Close();
	List<Dictionary<string, object>> output = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(response);
}
In my scratchpad app where I test new code, a winforms app running .NET 4.6.1, this works perfectly. When I copy and paste this exact code to where it needs to be, a web service running .NET 4.7.2, it errors out on the "using StreamReader" line, with error "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

I added the following lines right before the stream gets opened, because I'm just trawling StackOverflow and throwing in anything that's ever worked for anyone at this point:
code:
request.KeepAlive = true;
request.ProtocolVersion = HttpVersion.Version10;
request.ServicePoint.ConnectionLimit = 24;

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
System.Net.ServicePointManager.Expect100Continue = false;
None of it's helped. Can anyone think of any more reasons why perfectly good code would also be code that doesn't work?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

SirViver posted:

I'm 99% sure this is a TLS issue.
I've since copy and pasted the code into a 4.7.2 console app and it runs fine there, does that change your opinion at all? That's my current cop-out solution, just make a console app that works and have the web service run the console app.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
So I'm playing with .NET 5 now that it's out, and you can make .dbml files again, but there's no System.Data.Linq, so as far as I can tell, they don't frigging do anything.

Do I really have to go back to data connections, writing every query out, and assigning each result to a variable manually? Because I can, but man, I don't wanna.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

mystes posted:

Isn't that LINQ to SQL which has been deprecated for years (for some reason)?
Yeah, and then it's suddenly an option for a file again when you upgrade to .NET 5, so I thought maybe it'd be coming back as part of the Core/Framework integration.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Is Entity Framework a good solution for connecting to an existing SQL database that gets used by other stuff? The tutorials I read are all so hopped up about how it can auto-create tables for itself and I do not want it to do that. It also seems like my options are either that or going back to manually writing everything out using SqlCommand. What was so frigging wrong with linq to sql, anyway? I liked not having to manually write out the classes and do the mapping.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

spaced ninja posted:

Haven’t used EF in a while but pretty sure this is what you want. You can auto generate the entities from the db.

https://docs.microsoft.com/en-us/ef/ef6/modeling/designer/workflows/database-first
I started looking into this, and of course it's EF 6, not EF Core. I'm also trying to move to .NET 5, because I might as well rip off as many bandaids as possible at once and learn the stuff Microsoft's gonna demand I learn anyway. I guess I have to learn scaffolding too now?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I'm at my wit's end, can anyone explain to me how this is escaping error handling and what I can do to corral it? I have tested it with async code that does nothing but throw an exception and it can catch that, but when I do the HttpClient.GetAsync and it exceptions out, it's busting straight through.

code:
try
{
	Task.Run(async () =>
	{
		result = await client.GetAsync(url);
	}).Wait();
}
catch (Exception ex)
{
	//error handling
}

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Bruegels Fuckbooks posted:

Async void methods are a footgun for precisely this reason. The way the exception is rethrown is through the task. Without a task, it can't rethrow.
Okay, but what am I supposed to do about it? I don't even want to be calling the dang website asynchronously in the first place, the code's not doing anything until it gets that data, but HttpClient only frigging has GetAsync for reasons that are certainly beyond me.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

mystes posted:

Then get rid of task.run and just use .result?
Tried that first, it still merrily busts the try/catch because the error's in the async thread. Task.Run is me trying to force the entire thing onto one thread so I can catch the errors that sometimes come up during GetAsync, because I have no idea what's even triggering them, let alone how to prevent it, because it's outside the error handling.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Ola posted:

Can't you just go like this?

code:
try
{
	result = await client.GetAsync(url);
}
catch (Exception ex)
{
	//error handling
}
The calling function becomes async which may bubble up and cause some headaches.
It does bubble up, but I think it's worth trying and I'll risk the headaches. Good idea, thanks.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I've got a mobile app to rewrite at work and a really generous deadline, so I figured I'd take time and play with all the new toys, see what they're like. So I made a MAUI/Blazor hybrid app, and... this is a website. This is a literal, css-using, wwwroot-folder-having, website. They've somehow tricked it into running as a desktop or mobile app, but the code itself is pure website.

And I get what Microsoft is going for, right? If they can unify every design case into "just write it in this one language, we'll compile it appropriately for you", everyone's life gets appreciably easier. But it's been a loving decade since I did web development in any major capacity and it's a bit annoying that we've taken in all of web design's weaknesses too and jettisoned strengths of coding for apps, so now the codebehind just plain can't see anything you put on the razor pages, hope you didn't need sender in any of your event args.

Is it known to what degree this is gonna be the way things go in the future? Like, if Microsoft intends to continue the pressure to turn everything into a Blazor app, okay, gently caress it, I'll start learning web design. But if it's not, I... kinda don't want to.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

ChocolatePancake posted:

That said though, I doubt that Maui/Blazor is 'the' future. Blazor maybe, at least for non-tech companies it is very popular, but Maui really isn't good yet, and they don't have many people working on it. Doesn't seem like a big priority for them.
I mean, Xamarin is straight up EoL and out of support now; that's the entire reason I have a mobile app to rewrite, the old one was in Xamarin and it turns out it doesn't know how to handle local time zones in Android 14+. And MAUI seems pretty good. Is it 90% still Xamarin? Yeah, but the changes are all good, everything they've done has reduced the amount of platform-specific code you still need to write and platform switching is way cleaner as a result.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

mystes posted:

You can also just use MAUI. Hybrid apps are specifically for when you want to use MAUI to present a webview control for your blazor app

That's not to say I think MAUI is good or anything but the whole idea of hybrid apps is to use MAUI to do something like Cordova for blazor apps but within the MAUI / .net ecosystem and within that context the idea probably more or less makes sense.
Yeah, I know. I'm specifically wondering if I should do a hybrid app because it's likely that Microsoft will put more pressure on in the future to turn everything into Blazor -- because, like I said, I can see the benefit of literally everything being one codebase and they'll just compile it differently for us. If they're gonna, I'll go with it, but if they're not gonna, I really don't want to.

Adbot
ADBOT LOVES YOU

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Oh, we're doing Maui no question. I'm just looking ahead. Basically, if in five years Microsoft is gonna go "okay, everyone start using Blazor or whatever web language we've replaced it with for everything", I want to have spent those five years getting good at web development.

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