Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automate Tweets from curated data #7

Closed
BryanWilhite opened this issue Dec 30, 2019 · 11 comments
Closed

automate Tweets from curated data #7

BryanWilhite opened this issue Dec 30, 2019 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@BryanWilhite
Copy link
Owner

already tried 3rd-party solutions (e.g. HootSuite)

there are two recognized ways to do this in the Studio:

  1. use the Twitter Connector in Azure Logic Apps to send tweets driven on a scheduler and Azure Storage
  2. use LinqToTwitter in Azure Functions
@BryanWilhite BryanWilhite added the enhancement New feature or request label Dec 30, 2019
@BryanWilhite BryanWilhite self-assigned this Dec 30, 2019
BryanWilhite added a commit that referenced this issue Dec 30, 2019
@BryanWilhite
Copy link
Owner Author

before Tweets can be published a status has to be written which means HTML pages have to be parsed; the first library for this task is HtmlAgilityPack [NuGet] followed by other picks:

BryanWilhite added a commit that referenced this issue Dec 30, 2019
@BryanWilhite
Copy link
Owner Author

this exploration shows the shape of the data pulled from an HTML page: https://github.com/BryanWilhite/LinqPad/blob/master/Queries/funkyKB/HtmlAgilityPack%20-%20page%20parsing.linq

{
  "metaTwitterImage": "",
  "metaTwitterHandle": "",
  "metaTwitterTitle": "",
  "metaTwitterDescription": "",
  "metaOgImage": "",
  "metaOgTitle": "",
  "metaOgDescription": "",
  "title": ""
}

@BryanWilhite
Copy link
Owner Author

Test Name:	Songhay.Social.Shell.Tests.HtmlWebTests.ShouldLoad(location: "https://codeopinion.com/avoiding-nullreferenceexce"...)
Test Outcome:	Passed
Result StandardOutput:	
DocumentNode: <!doctype html>
<!--[if !IE]>
<html class="no-js non-ie" lang="en-US"> <![endif]-->
<!--[if IE 7 ]>
<html class="no-js ie7" lang="en-US"> <![endif]-->
<!--[if IE 8 ]>
<html class="no-js ie8" lang="en-US"> <![endif]-->
<!--[if IE 9 ]>
<html class="no-js ie9" lang="en-US"> <![endif]-->
<!--[if gt IE 9]><!-->
<html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#f2f2f2">
<link rel="profile" href="http://gmpg.org/xfn/11">

<title>Avoiding the NullReferenceException - CodeOpinion</title>

<!-- Google Tag Manager for WordPress by gtm4wp.com -->
<script data-cfasync="false" data-pagespeed-no-defer="" type="text/javascript">//<![CDATA[
var gtm4wp_datalayer_name="dataLayer";var dataLayer=dataLayer||[];
//]]></script>
<!-- End Google Tag Manager for WordPress by gtm4wp.com -->
<!-- This site is optimized with the Yoast SEO plugin v12.7.1 - https://yoast.com/wordpress/plugins/seo/ -->
<meta name="description" content="The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception.">
<meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1">
<link rel="canonical" href="https://codeopinion.com/avoiding-nullreferenceexception/">
<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="og:title" content="Avoiding the NullReferenceException - CodeOpinion">
<meta property="og:description" content="The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception.">
<meta property="og:url" content="https://codeopinion.com/avoiding-nullreferenceexception/">
<meta property="og:site_name" content="CodeOpinion">
<meta property="article:section" content=".NET">
<meta property="article:published_time" content="2017-10-12T14:28:56+00:00">
<meta property="article:modified_time" content="2017-10-26T14:48:01+00:00">
<meta property="og:updated_time" content="2017-10-26T14:48:01+00:00">
<meta property="og:image" content="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg">
<meta property="og:image:secure_url" content="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:description" content="The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception.">
<meta name="twitter:title" content="Avoiding the NullReferenceException - CodeOpinion">
<meta name="twitter:site" content="@codeopinion">
<meta name="twitter:image" content="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg">
<meta name="twitter:creator" content="@codeopinion">
<script type='application/ld+json' class='yoast-schema-graph yoast-schema-graph--main'>{"@context":"https://schema.org","@graph":[{"@type":"WebSite","@id":"https://codeopinion.com/#website","url":"https://codeopinion.com/","name":"CodeOpinion","description":"Thoughts of a Software Developer","potentialAction":{"@type":"SearchAction","target":"https://codeopinion.com/?s={search_term_string}","query-input":"required name=search_term_string"}},{"@type":"ImageObject","@id":"https://codeopinion.com/avoiding-nullreferenceexception/#primaryimage","url":"https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming.jpg","width":400,"height":300},{"@type":"WebPage","@id":"https://codeopinion.com/avoiding-nullreferenceexception/#webpage","url":"https://codeopinion.com/avoiding-nullreferenceexception/","inLanguage":"en-US","name":"Avoiding the NullReferenceException - CodeOpinion","isPartOf":{"@id":"https://codeopinion.com/#website"},"primaryImageOfPage":{"@id":"https://codeopinion.com/avoiding-nullreferenceexception/#primaryimage"},"datePublished":"2017-10-12T14:28:56+00:00","dateModified":"2017-10-26T14:48:01+00:00","author":{"@id":"https://codeopinion.com/#/schema/person/de0b5ae5ca94167b6121beef7df76224"},"description":"The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception."},{"@type":["Person"],"@id":"https://codeopinion.com/#/schema/person/de0b5ae5ca94167b6121beef7df76224","name":"Derek Comartin","image":{"@type":"ImageObject","@id":"https://codeopinion.com/#authorlogo","url":"https://secure.gravatar.com/avatar/4a704fe64406f37dfa0debd53e143a79?s=96&d=mm&r=g","caption":"Derek Comartin"},"sameAs":[]}]}</script>
<!-- / Yoast SEO plugin. -->

<link rel='dns-prefetch' href='//fonts.googleapis.com'>
<link rel='dns-prefetch' href='//s.w.org'>
<link rel="alternate" type="application/rss+xml" title="CodeOpinion &raquo; Feed" href="https://codeopinion.com/feed/">
<link rel="alternate" type="application/rss+xml" title="CodeOpinion &raquo; Comments Feed" href="https://codeopinion.com/comments/feed/">
<link rel="alternate" type="application/rss+xml" title="CodeOpinion &raquo; Avoiding the NullReferenceException Comments Feed" href="https://codeopinion.com/avoiding-nullreferenceexception/feed/">
		<script type="text/javascript">window._wpemojiSettings={"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"https:\/\/codeopinion.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.3.2"}};!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o<i.length;o++)t.supports[i[o]]=l(i[o]),t.supports.everything=t.supports.everything&&t.supports[i[o]],"flag"!==i[o]&&(t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&t.supports[i[o]]);t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&!t.supports.flag,t.DOMReady=!1,t.readyCallback=function(){t.DOMReady=!0},t.supports.everything||(n=function(){t.readyCallback()},a.addEventListener?(a.addEventListener("DOMContentLoaded",n,!1),e.addEventListener("load",n,!1)):(e.attachEvent("onload",n),a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&t.readyCallback()})),(r=t.source||{}).concatemoji?d(r.concatemoji):r.wpemoji&&r.twemoji&&(d(r.twemoji),d(r.wpemoji)))}(window,document,window._wpemojiSettings);</script>
		<style type="text/css">img.wp-smiley,img.emoji{display:inline!important;border:none!important;box-shadow:none!important;height:1em!important;width:1em!important;margin:0 .07em!important;vertical-align:-.1em!important;background:none!important;padding:0!important}</style>
	<link rel='stylesheet' id='wp-block-library-css' href='https://codeopinion.com/wp-includes/css/dist/block-library/style.min.css?ver=5.3.2' type='text/css' media='all'>
<link rel='stylesheet' id='fancybox-css' href='https://codeopinion.com/wp-content/plugins/fancybox-for-wordpress/assets/css/fancybox.css?ver=1.3.4' type='text/css' media='all'>
<link rel='stylesheet' id='inbound-shortcodes-css' href='https://codeopinion.com/wp-content/plugins/cta/shared/shortcodes/css/frontend-render.css?ver=5.3.2' type='text/css' media='all'>
<link rel='stylesheet' id='sparkling-bootstrap-css' href='https://codeopinion.com/wp-content/themes/sparkling/assets/css/bootstrap.min.css?ver=5.3.2' type='text/css' media='all'>
<link rel='stylesheet' id='sparkling-icons-css' href='https://codeopinion.com/wp-content/themes/sparkling/assets/css/fontawesome-all.min.css?ver=5.1.1.' type='text/css' media='all'>
<link rel='stylesheet' id='sparkling-fonts-css' href='//fonts.googleapis.com/css?family=Open+Sans%3A400italic%2C400%2C600%2C700%7CRoboto+Slab%3A400%2C300%2C700&#038;ver=5.3.2' type='text/css' media='all'>
<link rel='stylesheet' id='sparkling-style-css' href='https://codeopinion.com/wp-content/themes/sparkling/style.css?ver=2.4.2' type='text/css' media='all'>
<link rel='stylesheet' id='enlighter-local-css' href='https://codeopinion.com/wp-content/plugins/enlighter/resources/EnlighterJS.min.css?ver=3.10.0' type='text/css' media='all'>
<script type='text/javascript' src='https://codeopinion.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/fancybox-for-wordpress/assets/js/jquery.fancybox.js?ver=1.3.4'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/duracelltomi-google-tag-manager/js/gtm4wp-form-move-tracker.js?ver=1.11.2'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/themes/sparkling/assets/js/vendor/bootstrap.min.js?ver=5.3.2'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/themes/sparkling/assets/js/functions.js?ver=20180503'></script>
<script type='text/javascript'>//<![CDATA[
var cta_variation={"cta_id":null,"admin_url":"https:\/\/codeopinion.com\/wp-admin\/admin-ajax.php","home_url":"https:\/\/codeopinion.com","split_testing":"1","sticky_cta":"1","page_tracking":"off"};
//]]></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/cta/assets/js/cta-variation.js'></script>
<script type='text/javascript'>//<![CDATA[
var inbound_settings={"post_id":"5278","post_type":"post","variation_id":"0","ip_address":"104.174.140.11","wp_lead_data":{"lead_id":null,"lead_email":null,"lead_uid":null,"lead_nonce":null},"admin_url":"https:\/\/codeopinion.com\/wp-admin\/admin-ajax.php","track_time":"2019\/12\/30 22:27:06","page_tracking":"off","search_tracking":"off","comment_tracking":"off","custom_mapping":[],"is_admin":"","ajax_nonce":"e2bbe6297c"};
//]]></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/cta/shared/assets/js/frontend/analytics/inboundAnalytics.min.js'></script>
<link rel='https://api.w.org/' href='https://codeopinion.com/wp-json/'>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://codeopinion.com/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://codeopinion.com/wp-includes/wlwmanifest.xml"> 
<meta name="generator" content="WordPress 5.3.2">
<link rel='shortlink' href='https://codeopinion.com/?p=5278'>
<link rel="alternate" type="application/json+oembed" href="https://codeopinion.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fcodeopinion.com%2Favoiding-nullreferenceexception%2F">
<link rel="alternate" type="text/xml+oembed" href="https://codeopinion.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fcodeopinion.com%2Favoiding-nullreferenceexception%2F&#038;format=xml">

<!-- Fancybox for WordPress v3.2.5 -->
<style type="text/css">.fancybox-slide--image .fancybox-content{background-color:#fff}div.fancybox-caption{display:none!important}img.fancybox-image{border-width:10px;border-color:#fff;border-style:solid;height:auto}div.fancybox-bg{background-color:rgba(102,102,102,.3);opacity:1!important}div.fancybox-content{border-color:#fff}div#fancybox-title{background-color:#fff}div.fancybox-content{background-color:#fff}div#fancybox-title-inside{color:#333}div.fancybox-caption p.caption-title{display:inline-block}div.fancybox-caption p.caption-title{font-size:14px}div.fancybox-caption p.caption-title{color:#333}div.fancybox-caption{color:#333}div.fancybox-caption p.caption-title{background:#fff;width:auto;padding:10px 30px}div.fancybox-content p.caption-title{color:#333;margin:0;padding:5px 0}</style><script type="text/javascript">jQuery(function(){jQuery.fn.getTitle=function(){var arr=jQuery("a[data-fancybox]");jQuery.each(arr,function(){var title=jQuery(this).children("img").attr("title");var caption=jQuery(this).next("figcaption").html();if(caption&&title){jQuery(this).attr("title",title+" "+caption)}else if(title){jQuery(this).attr("title",title);}else if(caption){jQuery(this).attr("title",caption);}});}
var thumbnails=jQuery("a:has(img)").not(".nolightbox").not('.envira-gallery-link').not('.ngg-simplelightbox').filter(function(){return/\.(jpe?g|png|gif|mp4|webp|bmp|pdf)(\?[^/]*)*$/i.test(jQuery(this).attr('href'))});var iframeLinks=jQuery('.fancyboxforwp').filter(function(){return!/\.(jpe?g|png|gif|mp4|webp|bmp|pdf)(\?[^/]*)*$/i.test(jQuery(this).attr('href'))}).filter(function(){return!/vimeo|youtube/i.test(jQuery(this).attr('href'))});iframeLinks.attr({"data-type":"iframe"}).getTitle();thumbnails.addClass("fancyboxforwp").attr("data-fancybox","gallery").getTitle();iframeLinks.attr({"data-fancybox":"gallery"}).getTitle();jQuery("a.fancyboxforwp").fancyboxforwp({loop:false,smallBtn:false,zoomOpacity:"auto",animationEffect:"fade",animationDuration:500,transitionEffect:"fade",transitionDuration:"300",overlayShow:true,overlayOpacity:"0.3",titleShow:true,titlePosition:"inside",keyboard:true,showCloseButton:false,arrows:true,clickContent:false,clickSlide:"close",mobile:{clickContent:function(current,event){return current.type==="image"?"toggleControls":false;},clickSlide:function(current,event){return current.type==="image"?"close":"close";},},wheel:false,toolbar:true,preventCaptionOverlap:true,onInit:function(){},onDeactivate:function(){},beforeClose:function(){},afterShow:function(){},afterClose:function(){},caption:function(instance,item){var testing=jQuery(this).context.title;var caption=jQuery(this).data('caption')||'';if(item.type==='image'&&testing.length){caption=(caption.length?caption+'<br />':'')+'<p class="caption-title">'+testing+'</p>';}return caption;},afterLoad:function(instance,current){current.$content.append('<div class=\"fancybox-custom-caption inside-caption\" style=\" position: absolute;left:0;right:0;color:#000;margin:0 auto;bottom:0;text-align:center;background-color:#FFFFFF \">'+current.opts.caption+'</div>');},});})</script>
<!-- END Fancybox for WordPress -->

<!-- Google Tag Manager for WordPress by gtm4wp.com -->
<script data-cfasync="false" data-pagespeed-no-defer="" type="text/javascript">//<![CDATA[
var dataLayer_content={"pagePostType":"post","pagePostType2":"single-post","pageCategory":["dotnet","asp-net-core"],"pagePostAuthor":"Derek Comartin"};dataLayer.push(dataLayer_content);
//]]></script>
<script data-cfasync="false">//<![CDATA[
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.'+'js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-5HBSL2');
//]]></script>
<!-- End Google Tag Manager -->
<!-- End Google Tag Manager for WordPress by gtm4wp.com --><style type="text/css">a,#infinite-handle span,#secondary .widget .post-content a,.entry-meta a{color:#d33}a:hover,a:focus,a:active,#secondary .widget .post-content a:hover,#secondary .widget .post-content a:focus,.woocommerce nav.woocommerce-pagination ul li a:focus,.woocommerce nav.woocommerce-pagination ul li a:hover,.woocommerce nav.woocommerce-pagination ul li span.current,#secondary .widget a:hover,#secondary .widget a:focus{color:#000}.btn-default,.label-default,.flex-caption h2,.btn.btn-default.read-more,button,.navigation .wp-pagenavi-pagination span.current,.navigation .wp-pagenavi-pagination a:hover,.woocommerce a.button,.woocommerce button.button,.woocommerce input.button,.woocommerce #respond input#submit.alt,.woocommerce a.button,.woocommerce button.button,.woocommerce a.button.alt,.woocommerce button.button.alt,.woocommerce input.button.alt{background-color:#1e73be;border-color:#1e73be}.site-main [class*="navigation"] a,.more-link,.pagination>li>a,.pagination>li>span,.cfa-button{color:#1e73be}.cfa-button{border-color:#1e73be}.cfa{background-color:#1e73be}.cfa-button:hover a{color:#1e73be}.cfa-text{color:#fff}.cfa-button{border-color:#fff;color:#fff}.navbar.navbar-default,.navbar-default .navbar-nav .open .dropdown-menu>li>a{background-color:#f2f2f2}.navbar-default .navbar-nav>li>a,.navbar-default .navbar-nav.sparkling-mobile-menu>li:hover>a,.navbar-default .navbar-nav.sparkling-mobile-menu>li:hover>.caret,.navbar-default .navbar-nav>li,.navbar-default .navbar-nav>.open>a,.navbar-default .navbar-nav>.open>a:hover,.navbar-default .navbar-nav>.open>a:focus{color:#6b6b6b}@media (max-width:767px){.navbar-default .navbar-nav>li:hover>a,.navbar-default .navbar-nav>li:hover>.caret{color:#6b6b6b!important}}.navbar-default .navbar-nav>li:hover>a,.navbar-default .navbar-nav>li:focus-within>a,.navbar-nav>li:hover>.caret,.navbar-nav>li:focus-within>.caret,.navbar-default .navbar-nav.sparkling-mobile-menu>li.open>a,.navbar-default .navbar-nav.sparkling-mobile-menu>li.open>.caret,.navbar-default .navbar-nav>li:hover,.navbar-default .navbar-nav>li:focus-within,.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.active>.caret,.navbar-default .navbar-nav>.active>a:hover,.navbar-default .navbar-nav>.active>a:focus,.navbar-default .navbar-nav>li>a:hover,.navbar-default .navbar-nav>li>a:focus,.navbar-default .navbar-nav>.open>a,.navbar-default .navbar-nav>.open>a:hover,.navbar-default .navbar-nav>.open>a:focus{color:#1e73be}@media (max-width:767px){.navbar-default .navbar-nav>li.open>a,.navbar-default .navbar-nav>li.open>.caret{color:#1e73be!important}}.dropdown-menu{background-color:#1e73be}.navbar-default .navbar-nav .dropdown-menu>li:hover,.navbar-default .navbar-nav .dropdown-menu>li:focus-within,.dropdown-menu>.active{background-color:#1e73be}@media (max-width:767px){.navbar-default .navbar-nav .dropdown-menu>li:hover,.navbar-default .navbar-nav .dropdown-menu>li:focus,.dropdown-menu>.active{background:transparent}}body,.entry-content{color:#000}.entry-content{font-size:14px}</style><link rel="pingback" href="https://codeopinion.com/xmlrpc.php">		<style type="text/css">.navbar>.container .navbar-brand{color:#000}</style>
	<style type="text/css" id="custom-background-css">body.custom-background{background-color:#f2f2f2}</style>
	<link rel="icon" href="https://codeopinion.com/wp-content/uploads/2019/11/cropped-favicon-32x32.png" sizes="32x32">
<link rel="icon" href="https://codeopinion.com/wp-content/uploads/2019/11/cropped-favicon-192x192.png" sizes="192x192">
<link rel="apple-touch-icon-precomposed" href="https://codeopinion.com/wp-content/uploads/2019/11/cropped-favicon-180x180.png">
<meta name="msapplication-TileImage" content="https://codeopinion.com/wp-content/uploads/2019/11/cropped-favicon-270x270.png">

<!-- BEGIN ExactMetrics v5.3.10 Universal Analytics - https://exactmetrics.com/ -->
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-36956733-1','auto');ga('send','pageview');</script>
<!-- END ExactMetrics Universal Analytics -->
		<style type="text/css" id="wp-custom-css">body{margin-top:10px}blockquote{font-size:14px!important}@media (min-width:1200px){.container{width:1200px}.main-content-inner.col-sm-12.col-md-8{width:70%}#secondary.widget-area.col-sm-12.col-md-4{width:30%}}.menu-item-object-page{padding-top:20px!important}.navbar-default .navbar-nav>li>a{font-size:23px}</style>
		
</head>

<body class="post-template-default single single-post postid-5278 single-format-standard custom-background">
<a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>
<div id="page" class="hfeed site">

	<header id="masthead" class="site-header" role="banner">
		<nav class="navbar navbar-default
		" role="navigation">
			<div class="container">
				<div class="row">
					<div class="site-navigation-inner col-sm-12">
						<div class="navbar-header">


														<div id="logo">
																																<a href="https://codeopinion.com/"><script data-pagespeed-no-defer="">//<![CDATA[
(function(){for(var g="function"==typeof Object.defineProperties?Object.defineProperty:function(b,c,a){if(a.get||a.set)throw new TypeError("ES3 does not support getters and setters.");b!=Array.prototype&&b!=Object.prototype&&(b[c]=a.value)},h="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,k=["String","prototype","repeat"],l=0;l<k.length-1;l++){var m=k[l];m in h||(h[m]={});h=h[m]}var n=k[k.length-1],p=h[n],q=p?p:function(b){var c;if(null==this)throw new TypeError("The 'this' value for String.prototype.repeat must not be null or undefined");c=this+"";if(0>b||1342177279<b)throw new RangeError("Invalid count value");b|=0;for(var a="";b;)if(b&1&&(a+=c),b>>>=1)c+=c;return a};q!=p&&null!=q&&g(h,n,{configurable:!0,writable:!0,value:q});var t=this;function u(b,c){var a=b.split("."),d=t;a[0]in d||!d.execScript||d.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)a.length||void 0===c?d[e]?d=d[e]:d=d[e]={}:d[e]=c};function v(b){var c=b.length;if(0<c){for(var a=Array(c),d=0;d<c;d++)a[d]=b[d];return a}return[]};function w(b){var c=window;if(c.addEventListener)c.addEventListener("load",b,!1);else if(c.attachEvent)c.attachEvent("onload",b);else{var a=c.onload;c.onload=function(){b.call(this);a&&a.call(this)}}};var x;function y(b,c,a,d,e){this.h=b;this.j=c;this.l=a;this.f=e;this.g={height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};this.i=d;this.b={};this.a=[];this.c={}}function z(b,c){var a,d,e=c.getAttribute("data-pagespeed-url-hash");if(a=e&&!(e in b.c))if(0>=c.offsetWidth&&0>=c.offsetHeight)a=!1;else{d=c.getBoundingClientRect();var f=document.body;a=d.top+("pageYOffset"in window?window.pageYOffset:(document.documentElement||f.parentNode||f).scrollTop);d=d.left+("pageXOffset"in window?window.pageXOffset:(document.documentElement||f.parentNode||f).scrollLeft);f=a.toString()+","+d;b.b.hasOwnProperty(f)?a=!1:(b.b[f]=!0,a=a<=b.g.height&&d<=b.g.width)}a&&(b.a.push(e),b.c[e]=!0)}y.prototype.checkImageForCriticality=function(b){b.getBoundingClientRect&&z(this,b)};u("pagespeed.CriticalImages.checkImageForCriticality",function(b){x.checkImageForCriticality(b)});u("pagespeed.CriticalImages.checkCriticalImages",function(){A(x)});function A(b){b.b={};for(var c=["IMG","INPUT"],a=[],d=0;d<c.length;++d)a=a.concat(v(document.getElementsByTagName(c[d])));if(a.length&&a[0].getBoundingClientRect){for(d=0;c=a[d];++d)z(b,c);a="oh="+b.l;b.f&&(a+="&n="+b.f);if(c=!!b.a.length)for(a+="&ci="+encodeURIComponent(b.a[0]),d=1;d<b.a.length;++d){var e=","+encodeURIComponent(b.a[d]);131072>=a.length+e.length&&(a+=e)}b.i&&(e="&rd="+encodeURIComponent(JSON.stringify(B())),131072>=a.length+e.length&&(a+=e),c=!0);C=a;if(c){d=b.h;b=b.j;var f;if(window.XMLHttpRequest)f=new XMLHttpRequest;else if(window.ActiveXObject)try{f=new ActiveXObject("Msxml2.XMLHTTP")}catch(r){try{f=new ActiveXObject("Microsoft.XMLHTTP")}catch(D){}}f&&(f.open("POST",d+(-1==d.indexOf("?")?"?":"&")+"url="+encodeURIComponent(b)),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(a))}}}function B(){var b={},c;c=document.getElementsByTagName("IMG");if(!c.length)return{};var a=c[0];if(!("naturalWidth"in a&&"naturalHeight"in a))return{};for(var d=0;a=c[d];++d){var e=a.getAttribute("data-pagespeed-url-hash");e&&(!(e in b)&&0<a.width&&0<a.height&&0<a.naturalWidth&&0<a.naturalHeight||e in b&&a.width>=b[e].o&&a.height>=b[e].m)&&(b[e]={rw:a.width,rh:a.height,ow:a.naturalWidth,oh:a.naturalHeight})}return b}var C="";u("pagespeed.CriticalImages.getBeaconData",function(){return C});u("pagespeed.CriticalImages.Run",function(b,c,a,d,e,f){var r=new y(b,c,a,e,f);x=r;d&&w(function(){window.setTimeout(function(){A(r)},0)})});})();pagespeed.CriticalImages.Run('/mod_pagespeed_beacon','https://codeopinion.com/avoiding-nullreferenceexception/','8Xxa2XQLv9',true,false,'4_Wjqc1U_80');
//]]></script><img src="https://codeopinion.com/wp-content/uploads/2016/01/cropped-logo-10.png" height="76" width="377" alt="CodeOpinion" data-pagespeed-url-hash="4243066083" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"></a>
																																</div><!-- end of #logo -->

							<button type="button" class="btn navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
								<span class="sr-only">Toggle navigation</span>
								<span class="icon-bar"></span>
								<span class="icon-bar"></span>
								<span class="icon-bar"></span>
							</button>
						</div>



						<div class="collapse navbar-collapse navbar-ex1-collapse"><ul id="menu-menu" class="nav navbar-nav"><li id="menu-item-6483" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6483"><a href="/derek-comartin/">Consulting</a></li>
<li id="menu-item-5843" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5843"><a href="https://codeopinion.teachable.com/">Courses</a></li>
<li id="menu-item-6482" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6482"><a href="/talks/">Talks</a></li>
<li id="menu-item-6485" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6485"><a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"><i class="fab fa-youtube"></i></a></li>
<li id="menu-item-6484" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6484"><a href="https://twitter.com/codeopinion"><i class="fab fa-twitter"></i></a></li>
<li id="menu-item-6486" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6486"><a href="https://www.linkedin.com/in/dcomartin/"><i class="fab fa-linkedin-square"></i></a></li>
<li id="menu-item-4006" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4006"><a href="https://codeopinion.com/feed/"><i class="fa fa-rss"></i></a></li>
</ul></div>


					</div>
				</div>
			</div>
		</nav><!-- .site-navigation -->
	</header><!-- #masthead -->

	<div id="content" class="site-content">

		<div class="top-section">
								</div>

		<div class="container main-content-area">
						<div class="row side-pull-right">
				<div class="main-content-inner col-sm-12 col-md-8">

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

		<div class='code-block code-block-2' style='margin: 8px auto; text-align: center; display: block; clear: both;'>
<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Leaderboard -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-5145059823428118" data-ad-slot="4196246911"></ins>
<script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></div>
<article id="post-5278" class="post-5278 post type-post status-publish format-standard hentry category-dotnet category-asp-net-core">
		<div class="post-inner-content">
		<header class="entry-header page-header">

			<h1 class="entry-title ">Avoiding the NullReferenceException</h1>

			<div class="entry-meta">
				<span class="posted-on"><i class="fa fa-calendar-alt"></i> <a href="https://codeopinion.com/avoiding-nullreferenceexception/" rel="bookmark"><time class="entry-date published" datetime="2017-10-12T09:28:56-05:00">October 12, 2017</time><time class="updated" datetime="2017-10-26T09:48:01-05:00">October 26, 2017</time></a></span><span class="byline"> <i class="fa fa-user"></i> <span class="author vcard"><a class="url fn n" href="https://codeopinion.com/author/dcomartin/">Derek Comartin</a></span></span>
								<span class="cat-links"><i class="fa fa-folder-open"></i>
				 <a href="https://codeopinion.com/category/dotnet/" rel="category tag">.NET</a>, <a href="https://codeopinion.com/category/asp-net-core/" rel="category tag">ASP.NET Core</a>				</span>
								
			</div><!-- .entry-meta -->
		</header><!-- .entry-header -->

		<div class="entry-content">
			<p><a href="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming.jpg"><img class="alignright size-medium wp-image-5279" src="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg" alt="" width="300" height="225" srcset="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg 300w, https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming.jpg 400w" sizes="(max-width: 300px) 100vw, 300px" data-pagespeed-url-hash="547997332" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"></a>Easily, by a landslide, the most common exception I&#8217;ve run into in C# is the <code class="EnlighterJSRAW" data-enlighter-language="csharp">NullReferenceException</code>.  Second would be an <code class="EnlighterJSRAW" data-enlighter-language="csharp">InvalidOperationException</code>.  But <code class="EnlighterJSRAW" data-enlighter-language="csharp">NullReferenceException</code> wins as most occurred exception hands down.  This quick post shows how we can start avoiding the NullReferenceException.</p>
<p><strong>I despise null.  I despise null checks. </strong></p>
<p>What if there was a way to get rid of null checks?  Luckily there is.</p>
<p>Last year I was at a talk by Reid Evans, <a href="https://codeopinion.com/getting-started-with-functional-programming-in-f/">Getting Started with Functional Programming in F#.</a>   He touched on it and I&#8217;ve been using an implementation in C# ever since.</p>
<h3>Option</h3>
<blockquote><p>an <b>option type</b> or <b>maybe type</b> is a <a title="Parametric polymorphism" href="https://en.wikipedia.org/wiki/Parametric_polymorphism">polymorphic type</a> that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.</p></blockquote>
<p><strong>Optional Library</strong></p>
<p>For this example, I&#8217;m going to use the <a href="https://github.com/nlkl/Optional">Optional</a> package.  There are many similar type libraries available on NuGet, but this one is fairly feature rich and serves the purpose for my example.</p>
<h3>NullReferenceException</h3>
<p>So I&#8217;m going to walk through a trivial example of a ASP.NET Core application that is going to return some customer data.  The sample code below will throw a <code class="EnlighterJSRAW" data-enlighter-language="csharp">NullReferenceException</code> when the incoming <code class="EnlighterJSRAW" data-enlighter-language="csharp">customerId</code> is not found in our database.</p>
<div class="oembed-gist"><script src="https://gist.github.com/dcomartin/f33bd9b0e04572ba99c884bbd83d5539.js"></script><noscript>View the code on <a href="https://gist.github.com/dcomartin/f33bd9b0e04572ba99c884bbd83d5539">Gist</a>.</noscript></div>
<h3>Null Check</h3>
<p>Obvious answer is to wrap the return statement in an if statement to verify the customer returned from the <code class="EnlighterJSRAW" data-enlighter-language="csharp">_customerRepository</code> is not <code class="EnlighterJSRAW" data-enlighter-language="csharp">null</code>.  If it is, then return a <code class="EnlighterJSRAW" data-enlighter-language="csharp">404</code>.</p>
<div class="oembed-gist"><script src="https://gist.github.com/dcomartin/82d8456ad671697aa51abad381ba15e2.js"></script><noscript>View the code on <a href="https://gist.github.com/dcomartin/82d8456ad671697aa51abad381ba15e2">Gist</a>.</noscript></div>
<h3>Option</h3>
<p>Our <code class="EnlighterJSRAW" data-enlighter-language="csharp">CustomerRepository</code>, could&#8217;ve thrown a <code class="EnlighterJSRAW" data-enlighter-language="csharp">InvalidOperationException</code> or another type of exception if the customer didn&#8217;t exist.  But what if instead it returned an <code class="EnlighterJSRAW" data-enlighter-language="csharp">Option&lt;Customer&gt;</code> and never returned <code class="EnlighterJSRAW" data-enlighter-language="csharp">null</code>.</p>
<p>In the example below, our <code class="EnlighterJSRAW" data-enlighter-language="csharp">_customerRepository.GetOptionById(int)</code> now returns an <code class="EnlighterJSRAW" data-enlighter-language="csharp">Option&lt;Customer&gt;.</code> This now <strong>forces</strong> us to specify how to handle if there is a value, and if it is null.</p>
<div class="oembed-gist"><script src="https://gist.github.com/dcomartin/782ad05e27d613484eb4e1d2fe189c39.js"></script><noscript>View the code on <a href="https://gist.github.com/dcomartin/782ad05e27d613484eb4e1d2fe189c39">Gist</a>.</noscript></div>
<h3>Gateway</h3>
<p>Hopefully this a a simple example of the Option type and how it can be a gateway to removing null and <code class="EnlighterJSRAW" data-enlighter-language="csharp">NullReferenceException</code> from your code.  Take a deeper look at the <a href="https://github.com/nlkl/Optional">docs</a> for the Optional library as there are many other great examples.</p>
<p>Are you using an implementation of Option/Maybe?  Let me know in the comments or on Twitter.</p>
<a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-size="large" data-show-count="false">Follow @codeopinion</a><script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<div class='code-block code-block-3' style='margin: 8px auto; text-align: center; display: block; clear: both;'>
<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Leaderboard -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-5145059823428118" data-ad-slot="4196246911"></ins>
<script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></div>
					</div><!-- .entry-content -->

		<footer class="entry-meta">

			
		</footer><!-- .entry-meta -->
	</div>

	
</article><!-- #post-## -->

<div id="disqus_thread"></div>

	<nav class="navigation post-navigation" role="navigation" aria-label="Posts">
		<h2 class="screen-reader-text">Post navigation</h2>
		<div class="nav-links"><div class="nav-previous"><a href="https://codeopinion.com/brighter-mysql-command-store/" rel="prev"><i class="fa fa-chevron-left"></i> <span class="post-title">Brighter MySQL Command Store</span></a></div><div class="nav-next"><a href="https://codeopinion.com/porting-to-entity-framework-core/" rel="next"><span class="post-title">Porting to Entity Framework Core <i class="fa fa-chevron-right"></i></span></a></div></div>
	</nav>
		</main><!-- #main -->
	</div><!-- #primary -->

</div><!-- close .main-content-inner -->
<div id="secondary" class="widget-area col-sm-12 col-md-4" role="complementary">
	<div class="well">
				<aside id="custom_html-6" class="widget_text widget widget_custom_html"><div class="textwidget custom-html-widget"><center><a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-size="large" data-show-count="false">Follow @codeopinion</a><script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<a href="https://mvp.microsoft.com/en-us/PublicProfile/5002380" target="_new" rel="noopener noreferrer">
<img style="height: 140px;" src="https://codeopinion.com/wp-content/uploads/2018/06/Derek-2018.jpg" alt="Derek Comartin" data-pagespeed-url-hash="938562842" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"><img style="height: 140px;" src="https://codeopinion.com/wp-content/uploads/2017/01/MVP_Logo_Preferred_Cyan300_RGB_300ppi.png" alt="Microsoft MVP" data-pagespeed-url-hash="846890732" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"></a>
<br><br>
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channelid="UC3RKA4vunFAfrfxiJhPEplw" data-layout="full" data-count="default"></div>
</center></div></aside><aside id="media_image-2" class="widget widget_media_image"><a href="https://codeopinion.teachable.com/p/practical-asp-net-core-signalr"><img width="534" height="601" src="https://codeopinion.com/wp-content/uploads/2018/11/PracticalSignalRFree.png" class="image wp-image-5871  attachment-full size-full" alt="" style="max-width: 100%; height: auto;" srcset="https://codeopinion.com/wp-content/uploads/2018/11/PracticalSignalRFree.png 534w, https://codeopinion.com/wp-content/uploads/2018/11/PracticalSignalRFree-267x300.png 267w" sizes="(max-width: 534px) 100vw, 534px" data-pagespeed-url-hash="1883314514" onload="pagespeed.CriticalImages.checkImageForCriticality(this);"></a></aside><aside id="custom_html-4" class="widget_text widget widget_custom_html"><div class="textwidget custom-html-widget"><!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<style type="text/css">#mc_embed_signup{background:#fff;clear:left;font:14px Helvetica,Arial,sans-serif}</style>
<div id="mc_embed_signup">
<form action="https://chickendinner.us8.list-manage.com/subscribe/post?u=8949e11ec16e10c9de5d7d7fc&amp;id=26e3c0d722" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="">
    <div id="mc_embed_signup_scroll">
	<h2>Subscribe!</h2>
<div class="mc-field-group">
	<label for="mce-EMAIL">Email Address </label>
	<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
	<div id="mce-responses" class="clear">
		<div class="response" id="mce-error-response" style="display:none"></div>
		<div class="response" id="mce-success-response" style="display:none"></div>
	</div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_8949e11ec16e10c9de5d7d7fc_26e3c0d722" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>

<!--End mc_embed_signup--></div></aside><aside id="ai_widget-2" class="widget ai_widget"><div class='code-block code-block-1' style='margin: 8px auto; text-align: center; display: block; clear: both;'>
<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5145059823428118" data-ad-slot="6158187549"></ins>
<script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></div>
</aside><aside id="search-3" class="widget widget_search"><h3 class="widget-title">Search</h3>
<form role="search" method="get" class="form-search" action="https://codeopinion.com/">
  <div class="input-group">
	  <label class="screen-reader-text" for="s">Search for:</label>
	<input type="text" class="form-control search-query" placeholder="Search&hellip;" value="" name="s" title="Search for:">
	<span class="input-group-btn">
	  <button type="submit" class="btn btn-default" name="submit" id="searchsubmit" value="Search"><span class="glyphicon glyphicon-search"></span></button>
	</span>
  </div>
</form>
</aside><aside id="sparkling-cats-3" class="widget sparkling-cats"><h3 class="widget-title">Categories</h3>

	<div class="cats-widget">

		<ul>
			<li class="cat-item cat-item-2"><a href="https://codeopinion.com/category/dotnet/">.NET</a> <span>185</span>
</li>
	<li class="cat-item cat-item-57"><a href="https://codeopinion.com/category/net-core/">.NET Core</a> <span>96</span>
</li>
	<li class="cat-item cat-item-49"><a href="https://codeopinion.com/category/asp-net-core/">ASP.NET Core</a> <span>67</span>
</li>
	<li class="cat-item cat-item-58"><a href="https://codeopinion.com/category/roundup/">Roundup</a> <span>57</span>
</li>
	<li class="cat-item cat-item-6"><a href="https://codeopinion.com/category/cqrs/">CQRS</a> <span>51</span>
</li>
	<li class="cat-item cat-item-46"><a href="https://codeopinion.com/category/asp-net/">ASP.NET</a> <span>46</span>
</li>
	<li class="cat-item cat-item-5"><a href="https://codeopinion.com/category/architecture/">Architecture</a> <span>17</span>
</li>
	<li class="cat-item cat-item-14"><a href="https://codeopinion.com/category/practices/">Practices</a> <span>16</span>
</li>
	<li class="cat-item cat-item-1"><a href="https://codeopinion.com/category/uncategorized/">Uncategorized</a> <span>11</span>
</li>
	<li class="cat-item cat-item-12"><a href="https://codeopinion.com/category/patterns/">Patterns</a> <span>10</span>
</li>
		</ul>

	</div><!-- end widget content -->

		</aside>	</div>
</div><!-- #secondary -->
		</div><!-- close .row -->
	</div><!-- close .container -->
</div><!-- close .site-content -->

	<div id="footer-area">
		<div class="container footer-inner">
			<div class="row">
				
				</div>
		</div>

		<footer id="colophon" class="site-footer" role="contentinfo">
			<div class="site-info container">
				<div class="row">
										<nav role="navigation" class="col-md-6">
											</nav>
					<div class="copyright col-md-6">
						sparkling						Theme by <a href="http://colorlib.com/" target="_blank">Colorlib</a> Powered by <a href="http://wordpress.org/" target="_blank">WordPress</a>					</div>
				</div>
			</div><!-- .site-info -->
			<div class="scroll-to-top"><i class="fa fa-angle-up"></i></div><!-- .scroll-to-top -->
		</footer><!-- #colophon -->
	</div>
</div><!-- #page -->

		<script type="text/javascript">jQuery(document).ready(function($){if($(window).width()>=767){$('.navbar-nav > li.menu-item > a').click(function(){if($(this).attr('target')!=='_blank'){window.location=$(this).attr('href')}})}})</script>
	
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HBSL2" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) --><script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/cta/shared//shortcodes/js/spin.min.js'></script>
<script type='text/javascript'>//<![CDATA[
var countVars={"disqusShortname":"codeopinion"};
//]]></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/disqus-comment-system/public/js/comment_count.js?ver=3.0.17'></script>
<script type='text/javascript'>//<![CDATA[
var embedVars={"disqusConfig":{"integration":"wordpress 3.0.17"},"disqusIdentifier":"5278 https:\/\/codeopinion.com\/?p=5278","disqusShortname":"codeopinion","disqusTitle":"Avoiding the NullReferenceException","disqusUrl":"https:\/\/codeopinion.com\/avoiding-nullreferenceexception\/","postId":"5278"};
//]]></script>
<script src="https://codeopinion.com/wp-content/plugins,_disqus-comment-system,_public,_js,_comment_embed.js,qver==3.0.17+themes,_sparkling,_assets,_js,_skip-link-focus-fix.min.js,qver==20140222.pagespeed.jc.PDsy07_ZOI.js"></script><script>eval(mod_pagespeed_xYv114_mtZ);</script>
<script>eval(mod_pagespeed_mV3iu6vjX3);</script>
<script type='text/javascript' src='https://codeopinion.com/wp-includes/js/comment-reply.min.js?ver=5.3.2'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/enlighter/resources/mootools-core-yc.js?ver=3.10.0'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/enlighter/resources/EnlighterJS.min.js?ver=3.10.0'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-includes/js/wp-embed.min.js?ver=5.3.2'></script>
<script type='text/javascript' src='https://codeopinion.com/wp-content/plugins/oembed-gist/js/script.min.js?ver=4.9.1'></script>
<script type="text/javascript">//<![CDATA[
EnlighterJS_Config={"selector":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"language":"generic","theme":"enlighter","indent":2,"hover":"hoverEnabled","showLinenumbers":true,"rawButton":true,"infoButton":true,"windowButton":true,"rawcodeDoubleclick":false,"grouping":true,"cryptex":{"enabled":false,"email":"mail@example.tld"}};!function(){var a=function(a){var b="Enlighter Error: ";console.error?console.error(b+a):console.log&&console.log(b+a)};return window.addEvent?"undefined"==typeof EnlighterJS?void a("Javascript Resources not loaded yet!"):"undefined"==typeof EnlighterJS_Config?void a("Configuration not loaded yet!"):void window.addEvent("domready",function(){EnlighterJS.Util.Init(EnlighterJS_Config.selector.block,EnlighterJS_Config.selector.inline,EnlighterJS_Config)}):void a("MooTools Framework not loaded yet!")}();;
//]]></script>
</body>
</html>

metaTwitterImage: [null]
metaTwitterHandle: <meta name="twitter:site" content="@codeopinion">
metaTwitterTitle: <meta name="twitter:title" content="Avoiding the NullReferenceException - CodeOpinion">
metaTwitterDescription: <meta name="twitter:description" content="The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception.">
metaOgImage: <meta property="og:image" content="https://codeopinion.com/wp-content/uploads/2017/10/brace-yourself-nullreferenceexception-incoming-300x225.jpg">
metaOgTitle: <meta property="og:title" content="Avoiding the NullReferenceException - CodeOpinion">
metaOgDescription: <meta property="og:description" content="The most common exception encountered is the NullReferenceExeption. See how to use an option/maybe type in C# to start avoiding the NullreferenceEception.">
title: <title>Avoiding the NullReferenceException - CodeOpinion</title>

@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Dec 31, 2019

next moves:

  • verify that ExcelReaderFactory can distinguish Workbook pages
  • use the findings of ShouldReadTweetBook to read curated tweets into partitions and save as JSON
  • upload JSON to Azure Storage
  • determine whether Azure Logic Apps can connect to Azure Storage and read JSON (probably not)

@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jan 1, 2020

~1000 URIs processed in 18mins:
image

⚠️ ran into this issue: BryanWilhite/SonghayCore#87

@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jan 1, 2020

the curation of YouTube links leads to almost nothing:

  {
    "errorType": "",
    "errorMessage": "",
    "hasLoadError": false,
    "isPublished": false,
    "location": "https://www.youtube.com/watch?v=Xb_0awoShR8",
    "metaTwitterImage": null,
    "metaTwitterHandle": null,
    "metaTwitterTitle": null,
    "metaTwitterDescription": null,
    "metaOgImage": null,
    "metaOgTitle": null,
    "metaOgDescription": null,
    "status": "YouTube\r\n\r\n\r\n\r\nhttps://www.youtube.com/watch?v=Xb_0awoShR8\r\n\r\n#rxa 👁⚙🌩",
    "title": "YouTube"
  }

i assume YouTube is using some form of Angular that is obscuring data scraping

this, by the way, is the new, more Azure-Logic-Apps-friendly shape of the JSON

https://www.jsonschema.net/

BryanWilhite added a commit that referenced this issue Jan 1, 2020
@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jan 2, 2020

Microsoft still has not recognized changes in the Twitter API?
image

this constraint alone nudges me toward an Azure Durable Functions approach 🙄

oops! 🤦‍♂
image
https://www.onmsft.com/news/twitters-new-280-character-tweets-already-showing-on-windows-10-mobile-pc

BryanWilhite added a commit that referenced this issue Jan 2, 2020
BryanWilhite added a commit that referenced this issue Jan 2, 2020
@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jan 2, 2020

this post exceeds 280 chars:

Node.js Forked Again Over Complaints of Unresponsive Leadership - The New Stack

The codebase for popular Node.js JavaScript runtime has been forked again  — the second time in less than three years — with a growing number of contributors charging that the Technical Steering Comm…

https://thenewstack.io/node-js-forked-complaints-repeated-harassment/

#rxa 👁⚙🌩

this tells me that link-shortening must be run before posting

update: the title and description lines are 283 characters

@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jan 2, 2020

the responsibilities of Azure Logic Apps:

selecting the first file from an Azure Files listing

image

with this: first(body('Filter_only_files')).Path

parsing JSON with @string()

by default JSON is stores in Azure Files as application/octet-stream; this will cause the Parse JSON Action to fail

through trial and error i see that i need to explicitly set this:

string(body('Get_file_content'))

image

which the current Logic Apps UX reduces to:
image

The UX visualization makes no distinction between string(body('Get_file_content')) and body('Get_file_content'); the only way to tell that string() is there is to Peek Code and look for @string:
image

@string(body('Get_file_content'))

moving the processed JSON file with Azure File actions

image

BryanWilhite added a commit that referenced this issue Jan 2, 2020
BryanWilhite added a commit that referenced this issue Jan 2, 2020
BryanWilhite added a commit that referenced this issue Jan 3, 2020
BryanWilhite added a commit that referenced this issue Jan 3, 2020
@BryanWilhite
Copy link
Owner Author

the “run after” settings for Copy file* actions should include failure:
image

this is based on the assumption (going forward) that failures in posting tweets will not be due to data format errors (expected errors include quota excess)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant