Visual Studio 2017 launches to a black or invisible screen

So I am working along on a .NET project in Visual Studio 2017 on my Windows 10 Pro laptop, and all of a sudden when I launch the application, I get either a black window where the IDE should be, or the window area is transparent and I just see a shadow of the window edge. Very frustrating, as it was working fine the day before.

Finally I tracked it down to some kind of problem with a display driver. My laptop came preloaded with Intel and Nvidia display drivers and control panels, so I went into the computer management and disabled both the Intel and Nvidia display adapters. After rebooting, my screen still works, and magically I can see Visual Studio when I fire it up. Sure, there are some negatives to this, such as not being able to change the display resolution of the laptop panel, as the only choice in the dropdown is the native resolution of the panel. But at least I am able to once again get stuff done.

BTW, Happy Birthday to Joe Satriani. I hope Joe and the band make a tour stop somewhere near central Ohio soon. I saw the G3 tour last year in Cleveland, but there wasn’t enough Joe.

LINQ to SQL DBML file shows up as XML code in Visual Studio Community 2017

I have a project from a few years ago that I am looking back into again, and while it builds just fine in Visual Studio Community 2017, when I open the DBML file, I get a big XML file instead of a nice design surface with the data tables.

The solution to this issue is to install the correct component to handle this type of file. To do this, you need to exit Visual Studio IDE and then launch the Visual Studio Installer. Once there, click Modify, click the Individual components tab at the top, scroll down to the Code tools section, select LINQ to SQL tools so that there is a check mark next to it, and click the Modify button at the bottom right corner of the window. Once this finishes and you go back into Visual Studio, the DBML file should now show up as a design surface instead of XML source code.

BTW, a posthumous Happy Birthday to Gilda Radner, who left us far too soon.

Swift app crashes with dyld Library not loaded message

So you are humming along on your new Swift app, and all of a sudden, when you bring in a framework revision or try to deploy to a device, you suddenly start getting dyld: Library not loaded messages when the app tries to launch.

Most likely, the reason for this is that the setting for embedding the Swift standard libraries is turned off, and the app for some reason needs them. The fix is easy enough, just go into your build settings for your app and look for “Always Embed Standard Swift Libraries”. Turn this setting on for your app’s target, clean, and then try to run again.

BTW, Happy 20th Anniversary to the iMac, which was announced to the world by former Apple CEO Steve Jobs on this date in 1998. I have had a few iMacs through the years, and they are great machines.

Simple React Native networking

If you are doing some cross platform mobile development, and find yourself in need of doing some simple React Native networking, never fear, fetch is here.

Here is a simple example of what one of your React Native files might look like. Keep in mind that I have gutted out a bunch of stuff from this file just to keep it readable, but you should get the idea from the networking functions getMoviesFromApiAsync() and moviesResponse() below.

import React, { Component } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import Styles from './Styles'
 
export default class Home extends Component<{}> {
 
  constructor(props) {
    super(props);
  }
 
  static navigationOptions = {
    header: (
      <View style={Styles.header}>
        <View style={{flex:1.0,justifyContent:'center',alignItems:'center'}}>
          <Text style={Styles.locBtnText}> Title </Text>
        </View>
      </View>
    )
  };
 
  render() {
    return (
      <View style={Styles.container}>
        {/* Your stuff goes here */}
      </View>
    );
  }
 
  {/* Networking call done here */}
  getMoviesFromApiAsync() {
    return fetch('https://facebook.github.io/react-native/movies.json')
      .then(response => response.text())
      .then(text => this.moviesResponse(text))
      .catch((error) => {
        console.error(error);
      });
  }
 
  {/* Response comes in here */}
  moviesResponse(text) {
    this.setState({waitCursorShowing: false});
    console.log("Movies response: " + text);
  }
 
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor:'white',
    alignItems: 'center',
    justifyContent:'center'
  },
});

BTW, Happy Anniversary to 2001: A Space Odyssey, which debuted to the public 50 years ago today. Sure it is a little slow, but oh what a jump cut.

WWDC goat rodeo

I have an idea for Apple on how to avoid the whole WWDC goat rodeo in terms of the tickets lottery. There are so many developers that do not get a chance to go to the event due to seats being taken up by people who only attend the keynote.

So here’s a thought, have separate tickets for the keynote and for the rest of the event. See, I’m an idea person.

BTW, a posthumous Happy Birthday to Denton “Cy” Young, one of the greatest pitchers in the history of baseball, born this date in 1867.

Back to the future?

What kind of sorcery is going with my framework modification dates?

BTW, a posthumous Happy Birthday to Mr. Fabulous, Alan Rubin. I feel the need now to go and watch Blues Brothers for like the 500th time.

Visual Studio Community 2017 crashes when running application

If you have Visual Studio Community 2017 and it crashes when you try running an application, I have heard that you can solve the problem by making sure that the .NET Framework 4.7.1 package is installed on your Windows machine.

BTW, Happy Birthday to the Great One, Wayne Gretzky.

Advent of Code 2017

Well this year’s Advent of Code 2017 must have been easier than the past two years. Either that, or I am getting better at this software development thing, as I am actually finished with it on the final day of the challenge. Huzzah!

Please feel free to check out my Github site for all the Swift 4 goodness needed to solve the 25 challenges:

https://github.com/Wave39/AdventOfCode2017

BTW, Merry Christmas (or insert your own holiday here) to all, and here’s hoping your 2018 is the best it can be.

Background thread URL download in Swift 4

I was recently working on a project in swift, and was not able to quickly find a way to use a background thread to do a URL download in Swift 4. There were plenty of snippets and tutorials out there, but they were all for older versions of Swift. (BTW Swift, you have to stop it with these breaking changes.)

So here is what I cobbled together to download from the OpenAQ web site, which has an open API to provide air quality data.

The Swift class that does the downloading and processing of the data from the site is this class, which I called OpenAQ.swift:

//
//  OpenAQ.swift
//  openaq
//
//  Created by Brian Prescott on 11/16/17.
//  Copyright © 2017 Brian Prescott. All rights reserved.
//
 
import UIKit
 
class OpenAQResult: NSObject {
    var city: String = ""
    var count: Int = 0
    var country: String = ""
    var locations: Int = 0
}
 
protocol OpenAQDelegate: class {
    func didFinish(sender: Any)
    func didError(sender: Any)
}
 
class OpenAQ: NSObject {
 
    weak var delegate:OpenAQDelegate?
    var returnValue: [OpenAQResult] = []
 
    func readDataBackground() -> Void {
        let urlString = "https://api.openaq.org/v1/cities?limit=10000"
        guard let url = URL(string: urlString) else { return }
        URLSession.shared.dataTask(with: url) { (data, res, err) in
 
            guard let data = data else {
                return
            }
 
            do {
 
                let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
                let resultsArray = json["results"] as! NSArray
                var retval: [OpenAQResult] = []
                for x in resultsArray {
                    let dict = x as! NSDictionary
                    let res = OpenAQResult()
                    res.city = dict.value(forKey: "city") as! String
                    res.count = dict.value(forKey: "count") as! Int
                    res.country = dict.value(forKey: "country") as! String
                    res.locations = dict.value(forKey: "locations") as! Int
                    if (res.count >= 10000) {
                        retval.append(res)
                    }
                }
                self.returnValue = retval.sorted(by: { $0.count > $1.count })
                self.delegate?.didFinish(sender: self)
            } catch {
                print("An error occurred")
            }
 
        }.resume()
    }
 
}

So then to use this class, here is a template of what your main view controller (or wherever you want to use it) would look like:

class MasterViewController: UITableViewController {
 
    var detailViewController: DetailViewController? = nil
    var objects = [OpenAQResult]()
    var openAQ: OpenAQ? = nil
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        openAQ = OpenAQ()
        openAQ?.delegate = self
        openAQ?.readDataBackground()
 
        // do the rest of your initialization
    }
 
    // the rest of your class would go here
 
}
 
extension MasterViewController: OpenAQDelegate {
    func didError(sender: Any) {
        print ("An error occurred!!!")
    }
 
    func didFinish(sender: Any) {
        objects = (sender as! OpenAQ).returnValue
        if (objects.count == 0) {
            let alert = UIAlertController(title: "Error", message: "The data could not be loaded. Please establish an internet connection and press the Refresh button above.", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
 
        DispatchQueue.main.async {
            // do something here
            // for example, reload a table view
        }
    }
}

In the code above, when the didFinish method is called, the objects instance variable is retrieved from the openAQ variable, and you can then do something with the data you just retrieved.

BTW, Happy Thanksgiving to all my U.S. readers. It has been a very trying year personally and all around, but we still have so much to be thankful for.

Plain ol’ XML

So let’s say you are working on an application in the .NET sphere of influence, and you have an object that you want to turn into XML. However, you shoot it through an XmlSerializer and you think you are done.

Ugh, what’s all that cruft in the XML stream?

Well there are some options you can play with to get rid of the extra stuff and just get plain ol’ XML. Here is a code snippet, where you will pass in your own object instead of the generic Order as shown below:

public String GetPlainOldXML(Order order)
{
    var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
    var settings = new XmlWriterSettings();
    settings.OmitXmlDeclaration = true;
 
    XmlSerializer xsSubmit = new XmlSerializer(typeof(Order));
    var xmlString = "";
    using (var sww = new StringWriter())
    {
        using (XmlWriter writer = XmlWriter.Create(sww, settings))
        {
            xsSubmit.Serialize(writer, order, emptyNamepsaces);
            xmlString = sww.ToString();
        }
    }
 
    return xmlString;
}

BTW, Happy Birthday to Leslie West of Mountain fame.