Xamarin PCL – How to URL Encode since there is no HttpUtility

Looking for the HTTPUtility class? Ha, you don’t get it. PCL doesn’t have it. Fret not, though, you can still URL Encode.

It’s easy, just in a different spot.

How to URLEncode in Xamarin Forms PCL

var encodedData = System.Net.WebUtility.UrlEncode(stuffToEncode);

Now you know, and now hopefully I will remember!

Happy coding!

Visual Studio 2015 error “Object reference not set to an instance of an object”

This fixed my razor intellisense problem and the error after installing the latest ASP.NET tools.

Here is how to fix it.

Delete the contents from the following folders:
C:\Users{user}\AppData\Local\Microsoft\VisualStudio
C:\Users{user}\AppData\Local\Microsoft\VSCommon

Navigate to the command line now and run devenv from either of these paths:
[x64] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
[x86] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE

run devenv /resetuserdata from the command prompt.

Thanks to fka for the steps!

https://stackoverflow.com/questions/34084003/visual-studio-2015-error-object-reference-not-set-to-an-instance-of-an-object/34085345#34085345

Happy Coding!

Reset performance counters when getting errors in Perfmon or Load Center

Old thing I was working on over a year ago. Well, maybe it is useful to someone:

 

PS C:\Windows\system32> cmd
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Windows\system32>lodctr /R

Error: Unable to rebuild performance counter setting from system backup store, error code is 2
C:\Windows\system32>cd ..

C:\Windows>cd syswow64

C:\Windows\SysWOW64>lodctr /R

Info: Successfully rebuilt performance counter setting from system backup store
C:\Windows\SysWOW64>winmgmt.exe /RESYNCPERF

C:\Windows\SysWOW64>

Value was either too large or too small for a UInt32. TFS Error

I got this error in Visual Studio 2015 checking in to TFS.
“Value was either too large or too small for a UInt32.”

WTF? Turns out it is because I had an open sql query file that wasn’t saved and it get angry.

Really stupid error that should read :” You have an saved file, please save all files before checking in”

Wow. That would have taken the developer a small minute. Oh yeah, this is probably an unhandled exception, caught higher up and presented to us as an amazing insight into what was wrong.

Anyway, Save All before checking in and you will be fine.

Happy Coding!

Unity 2D – How to anchor a sprite to the left side of the camera viewport

using UnityEngine;
using System.Collections;

public class ActualHeroController : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
float camHalfHeight = Camera.main.orthographicSize;
float camHalfWidth = Camera.main.aspect * camHalfHeight;

Bounds bounds = GetComponent().bounds;

// Set a new vector to the top left of the scene
Vector3 topLeftPosition = new Vector3(-camHalfWidth, 0, 0) + Camera.main.transform.position;

// Offset it by the size of the object
topLeftPosition += new Vector3(bounds.size.x / 2,-bounds.size.y / 2, 0);
topLeftPosition.z = 0;
transform.position = topLeftPosition;
}
}

How to call a function in Oracle in .NET, not a stored procedure

Ever think it would be oh so simple to call a function on an Oracle Database? So did I. I am normally writing SQL code for Microsoft SQL Server, but we also integrate with other systems who run Oracle.

I needed to call a function on the Oracle database to retrieve certain data. So I plugged it in thinking I could call it with a simple select. Wrong.

It is still simple, just had a little extra to the select to make it work.

OracleCommand command = provider.Connection.CreateCommand();
command.CommandType = System.Data.CommandType.Text;

//set sp name
command.CommandText = string.Format("Select PKG_NAME.VALIDATE({0}) from dual", id) ;

int returnValue = (int)(decimal)command.ExecuteScalar();
return returnValue ==1;

Hopefully this helps you out. Pretty simple to do, just a matter of knowing how to do it.

Happy Coding!