Skip to content

Instantly share code, notes, and snippets.

View thdotnet's full-sized avatar

Thiago Custodio thdotnet

  • Xpirit USA
  • Texas, USA
View GitHub Profile
@thdotnet
thdotnet / gist:7252193
Created October 31, 2013 15:59
Based on @tucaz's project "https://github.com/tucaz/XmlToObjectParser", I decided to do the oposite, ExpandoObject to XML. Enjoy http://twitter.com/thdotnet
using System;
using System.Dynamic;
using System.Xml.Linq;
namespace ConsoleApplication5
{
internal class ToXml
{
public string GetXml(ExpandoObject obj, XElement rootElement)
{
@thdotnet
thdotnet / gist:b389ad252552368f5171
Created June 10, 2015 14:03
Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure
Today I've faced a problem with Microsoft.WindowsAzure.Storage nuget package. Running the application I've got the following runtime exception:
"Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0..."
I've found some blog posts that says to use binding redirect to Version 5.6.4.0. However, only configuring the binding redirect of this version will not fix the error, When I've published my application to Azure, I've saw a message on the output window:
1>------ Build started: Project: XXX, Configuration: Release Any CPU ------
1> Consider app.config remapping of assembly "Microsoft.Data.Edm, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "5.6.2.0" [] to Version "5.6.4.0" [C:\Users\br.thiago.custodio\documents\visual studio 2013\Projects\XXX\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll] to solve conflict and get rid of warning.
1> Consider app.config remapping of assembly "Microsoft.Data.Services.Client, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
@thdotnet
thdotnet / gist:0a94e688dd3e6a14b4d75edd54474c55
Last active October 29, 2016 10:48
Packages to Secure Web App with Azure AD
Install-Package Microsoft.IdentityModel.Protocol.Extensions
Install-Package System.IdentityModel.Tokens.Jwt
Install-Package Microsoft.Owin.Security.OpenIdConnect
Install-Package Microsoft.Owin.Security.Cookies
Install-Package Microsoft.Owin.Host.SystemWeb
@thdotnet
thdotnet / gist:dbb3afdd831582721b3096247ca5193b
Last active November 2, 2016 09:00
Webapi Route Prefix
public class ApiVersion1RoutePrefixAttribute : RoutePrefixAttribute
{
private const string RouteBase = "api/{apiVersion:apiVersionConstraint(v1)}";
private const string PrefixRouteBase = RouteBase + "/";
public ApiVersion1RoutePrefixAttribute(string routePrefix)
: base(string.IsNullOrWhiteSpace(routePrefix) ? RouteBase : PrefixRouteBase + routePrefix)
{
}
}
@thdotnet
thdotnet / Distinct By
Created November 24, 2016 11:17
Linq Distinct By implementation
using System;
using System.Collections.Generic;
using System.Linq;
namespace Testes
{
class Program
{
static void Main(string[] args)
{
@thdotnet
thdotnet / gist:d5c0b2320e6b90700b85bd0b4876dc64
Created January 11, 2017 03:43
c# code to read and update session values persisted into Sql Server
private static void ReadShortSessionItem(SqlBytes SessionItemShort)
{
using (MemoryStream ms = new MemoryStream(SessionItemShort.Buffer))
{
using (BinaryReader br = new BinaryReader(ms))
{
var sessionTimeout = br.ReadInt32();
bool sessionDataExists = br.ReadBoolean();
bool containsStaticObjects = br.ReadBoolean();
@thdotnet
thdotnet / gist:58d3682ebfd5f72473a0a73e938d4358
Created January 18, 2017 22:07
Update Microsoft.Owin fix
Problem with Microsoft.Owin 2.0.1
Update-Package Microsoft.Owin -Reinstall
@thdotnet
thdotnet / gist:8e07cf73026bafddb3491919c9dabc70
Created February 22, 2017 09:22
Fix HttpContext.Current sometimes null
Sometimes the root cause of HttpContext.Current null is the missing <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> in the web.config
@thdotnet
thdotnet / gist:1eb1b8414606329e2db1f87dfc54afb6
Created October 2, 2017 20:34
MSBuild Error for Service Fabric projects
Here are the steps I followed to resolve the issue.
Right click on (load Failed) project and edit in visual studio.
Saw the following line in the Project tag: <Project Sdk="Microsoft.NET.Sdk.Web" >
Followed the instruction shown in the error message to add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to this tag
source: https://stackoverflow.com/a/44785842/1384539
public static class StringExtensions
{
private delegate bool TryParseDelegate<T>(string s, out T result);
private static T To<T>(string value, TryParseDelegate<T> parse)
=> parse(value, out T result) ? result : default;
public static int ToInt32(this string value)
=> To<int>(value, int.TryParse);