Damir Dobric PostsMy corner on advanced Windows Developmenthttp://developers.de/blogs/damir_dobric/atom.aspxCommunity Server2017-07-16T10:16:44ZLoad Balancing on Azure/blogs/damir_dobric/archive/2017/10/24/load-balancing-on-azure.aspx2017-10-24T05:57:00Z2017-10-24T05:57:00Z<p>Microsoft Azure support two different kind of Load Balancer configurations. For all internet traffic coming from outside into the Azure you will have to use so called “Internet Facing Load balancer”.</p> <p>All traffic between virtual machines hosted in azure is controlled by “Internal Load balancer”. Currently, there are 3 Load Balancers in Azure:</p> <p>- Azure Load Balancer <br />- Application Gateway <br />- Traffic Manager</p> <h3>Azure Load Balancer</h3> <p>This kind of load balancer supports internet-facing LB and internal LB. It is implemented at Layer 4 and supports any application protocol. It is usually used in conjunction with Azure VNets.</p> <p>IF-LB uses so called hash-based distribution algorithm to distribute incoming public traffic as shown at the picture below:</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_66F5E142.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_3BB14A3B.png" width="344" height="327" /></a></p> <p>The picture shows that traffic is distributed from publish source to internal (in Azure) destination, but it doesn’t describe how.</p> <p>This LB supports two different algorithms to distribute the traffic. They are also called <a href="https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-distribution-mode">distribution modes</a>. <br />Currently are supported two distribution modes:</p> <p>- Hash Based Distribution Mode <br />- IP Affinity Distribution Mode</p> <h4>Hash Based Distribution Mode</h4> <p>It uses (by default) a hash composed over 5 variables:</p> <p>- Source IP <br />- Source Port <br />- Destination IP <br />- Destination port <br />- Protocol type</p> <h4>IP Affinity Distribution Mode</h4> <p>IP Affinity mode sticks the session from source to destination. If can be configured to use Source-UP and Destination-IP to set the sticky session. Once the session is established, LB makes sure that all traffic is routed to the same destination.</p> <p>In some scenarios affinity mode can be set to use also port number as 3th parameter for affinity session.</p> <h3>Application Gateway</h3> <p>Application Gateway is a service, which represents so called Application Delivery Controller as a service. It is a gateway with bunch of features in front of some application, which is running behind some dedicated IP address. Because it acts in front of application, it supports various load-balancing features at application level 7. Note that Azure Load balancer is working on lower-level 4.</p> <p>Application Gateway supports round robin distribution, cookie-based session affinity, URL path-based routing, and the ability to host multiple websites behind a single gateway endpoint.</p> <p>From the architecture point of view, gateway looks same as LB (se previous picture).</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_34920DC3.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_373AC974.png" width="343" height="188" /></a></p> <p>But note, that is is running on higher level. Incoming traffic is now HTTP/S and not some proprietary TCP or UDP protocol. Application Gateway is used for load balancing of HTTP, HTTP/S and WebSocket traffic. Because gateway knows everything about application protocols it can provide protocol dedicated features. For example,, this can be SSL offloading (SSL decryption and termination, then routing to application) or URL-based routing. <br />Such features are not supported by Load Balancer.</p> <p> <br />It is also remarkable that gateway can set policy for using of dedicated <a href="https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-ssl-policy-overview">CipherSuite</a>.</p> <p>More over it provides <a href="https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-web-application-firewall-overview">Web Application Firewall</a> as integrative part. Such firewalls protect an application from set of different vulnerabilities defined by <a href="https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project">OWASP</a> rules. Some of rules are: SQL Injection , Cross Site Scripting , HTTP Protocol Violations and many others.</p> <p>For more information about Application Gateway take a look <a href="https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-introduction">here</a>.</p> <h3>Traffic Manager</h3> <p>Unlike to Load Balancer and Application Gateway, Traffic Manager uses DNS *Domain Name System) to direct requests. Requests can be directed to various endpoints like VMs, WebApps, Cloud Services or some external services (from Azure point of view). Following picture shows how Traffic Manager looks up the DNS in request and chose some of destination endpoints based on set of routing method rules.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_022E3A44.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_4BC018F2.png" width="614" height="317" /></a></p> <p>Core of Traffic Manager is Distribution of traffic according to one of traffic routing methods. For example, if you want to route all your traffic to a single endpoint, but you want to provide a failover endpoint, you will use so called priority routing. If you have 3 destinations, priority routing will chose the destination with highest priority as long it is online. If Primary fails, then next would be Node A, because priority 2 is higher than 3.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_728E2F32.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_3D81A002.png" width="244" height="109" /></a></p> <p>If you want to evenly distribute traffic, you will use weighted routing. In following example traffic will ve evenly distributed to Nodes A and B.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_794138B5.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_7221FC3D.png" width="244" height="108" /></a></p> <p>If your application is installed on different locations some kind of performance-based routing measured by DNS queries might be useful.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_6B02BFC5.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_11D0D606.png" width="335" height="103" /></a></p> <p>Traffic Manager looks up the source IP address of the incoming DNS request in the Internet Latency Table. Traffic Manager chooses an available endpoint in the Azure datacenter that has the lowest latency for that IP address range, then returns that endpoint in the DNS response.</p> <p>Last, but not leas, you can use routing dependent on geographic region. Depending on from where request do come from, you can chose dedicated endpoints.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_4D906EB9.png"><img title="image" style="margin-right:auto;margin-left:auto;float:none;display:block;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_46713241.png" width="244" height="119" /></a></p> <p>For more information about Traffic Manager take a look <a href="https://docs.microsoft.com/en-us/azure/traffic-manager/traffic-manager-routing-methods">here</a>.</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809839" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxAGENDA .NETConf in Frankfurt Oct.2017/blogs/damir_dobric/archive/2017/10/12/agenda-netconf-in-frankfurt-oct-2017.aspx2017-10-12T09:54:11Z2017-10-12T09:54:11Z <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_714D3234.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_46089B2D.png" width="793" height="415" /></a></p> <h4>Covered Topics:</h4> <p>.NET Core Intro</p> <p>Frameworks and Runtime</p> <p>Creating .NET Core Framework Dependent Applications</p> <p>Creating .NET Core Self Contained Applications</p> <p>.NET Core and Docker</p> <p>Creating UI with .NET Core</p> <p>.NET Foundation</p> <p>.NET Standard and runtimes</p> <p>Machine Learning with .NET Core</p> <p>HoloLens, Unity3D, and .NET – a Mixed Reality with sprinkles of .NET Core</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809630" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxCannot install .NET Core on Ubuntu?/blogs/damir_dobric/archive/2017/10/09/cannot-install-net-core-on-ubuntu.aspx2017-10-09T05:33:00Z2017-10-09T05:33:00Z<p>When trying to install .NET Core on Ubuntu as described <a href="https://www.microsoft.com/net/core#linuxubuntu">here</a>, with following command:</p> <p><strong>sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'</strong></p> <p>you might get following error: </p> <p><font color="#ff0000"><em>Failed to fetch </em></font><a href="https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod/dists/xenial/InRelease"><font color="#ff0000"><em>https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod/dists/xenial/InRelease</em></font></a></p> <p>To workaround this issue register feed through HTTP instead of HTTS:</p> <p><strong>sudo sh -c 'echo "deb [arch=amd64] <font size="3">http</font>://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'</strong></p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809525" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspx.NET Core Deep Dive/blogs/damir_dobric/archive/2017/10/07/net-core-deep-dive.aspx2017-10-07T09:30:18Z2017-10-07T09:30:18Z<p>Microsoft .NET Conf is partnering with Azure Meetup Frankfurt and will organize around the globe many local in-person events between September 19 through the end of October! </p> <p>For more information please refer <a href="https://www.dotnetconf.net/local-events">here</a>.</p> <p>You can join us to learn more about .NET and the new .NET Core 2.0 release.</p> <p>We will start at Oct.12 at 4pm and end as usual around 8pm.</p> <p>Content will be delivered by:</p> <p>- Andreas Erben (<a href="https://www.linkedin.com/in/andreaserben/">Mixed Reality Architect, MVP</a>)</p> <p>- Andreas Lehmann (Cloud Solution Architect - daenet GmbH)</p> <p>- Mofaggol Hoshen (University of Applied Sciences Frankfurt am Main)</p> <p>- Sebastian Valero-Graefe (DevOp - daenet GmbH)</p> <p>- Jon Galloway (.<a href="https://twitter.com/jongalloway">NET Foundation executive director</a> )</p> <p>- Damir Dobric (MVP, RD <a href="https://about.me/damirdobric">https://about.me/damirdobric</a> )</p> <p><a href="https://twitter.com/jongalloway">Jon Galloway </a>.NET Foundation executive director will join us via Skype and talk about .NET Momentum.</p> <p>Hope to see you there. We will have some food and drinks and lot of goodies sent from Redmond (T-Shirts, stickers, etc.. :)</p> <p><img src="https://secure.meetupstatic.com/photos/event/6/e/9/b/600_464668315.jpeg" alt="" /></p> <p><b>AGENDA</b></p> <p>1.  .NET Core as Cloud Dev Framework: Why and What?</p> <p>2. .NET Standard and runtimes</p> <p>3. Creating .NET Core Framework Dependent Applications</p> <p>4. Creating .NET Core Self Contained Applications</p> <p>5. Deploying and running .NET Core on different operative systems</p> <p>6. Creating UI with .NET Core</p> <p>7. .NET Core and Containers</p> <p>8. Testing .NET Core Applications</p> <p>9. HoloLens, Unity3D, and .NET – a Mixed Reality with sprinkles of .NET Core</p> <p>10. Machine Learning with .NET Core</p> <p>Come together / Dinner</p> <p><b>Please note that you have to provide your valid ID at registration desk at e-Shelter. Usually if all attendees arrive  just few minutes before event, registration might take 15-30 minutes. Please be on time at e-shelter facility.</b></p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809521" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspx.NET Core: 'Publish' target is not supported/blogs/damir_dobric/archive/2017/09/19/net-core-publish-target-is-not-supported.aspx2017-09-19T04:35:00Z2017-09-19T04:35:00Z<p>When you are building Self Contained Deployments, sometimes the publish process cannot resolve the target framework. For example:</p> <p>dotnet publish -r win10-x64 </p> <p>dotnet publish -r win10-x64 --self-contained </p> <p>In this case you will get following error:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p><font color="#ff0000">Error : <br />The 'Publish' target is not supported without specifying a target framework. <br /></font><font color="#ff0000">The current project targets multiple frameworks, please specify the framework for the published application.</font> </p> </td> </tr> </table> <p>To workaround this error, you have to explicitly specify the target framework.</p> <p>dotnet publish -r win10-x64 --self-contained <strong>-f netcoreapp2.0</strong></p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809082" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspx.NET Cross-Framework referencing/blogs/damir_dobric/archive/2017/09/17/net-cross-framework-referencing.aspx2017-09-17T15:24:48Z2017-09-17T15:24:48Z<p>Assume, there is a .NET Framework application called <strong>NetDesktopApp</strong> and .NET Core library <strong>NetCoreLib2</strong>. <br />Further, <strong>NetCoreDesktopApp</strong> references <strong>NetCoreLib2. <br /></strong> Implementation of <strong>NetCoreLib2</strong> looks like:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p>using System;</p> <p>namespace NetCoreLib2 <br /> { <br />    public class MyNetCoreLib2 <br />    { <br />        public static string Go(long a) <br />        { <br />            return a++.ToString(); <br />        } <br />    } <br /> }</p> </td> </tr> </table> <p>Implementation of <strong>NetCoreDesktopApp</strong> looks like:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p>namespace NetDesktopApp <br /> { <br />    class Program <br />    { <br />         static void Main(string[] args) <br />        {       <br />            Console.WriteLine(MyNetCoreLib2.Go(DateTime.Now.Ticks)); <br />         } <br />    }</p> </td> </tr> </table> <p>When a .NET application starts, then following libraries are loaded.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_5ABB02FB.png"><img title="image" style="margin:0px;display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_539BC683.png" width="224" height="121" /></a></p> <p>Please note assembly <strong>netstandard.dll.</strong> This assembly is implicitly injected in the project by Visual Studio, when .NET Core assembly is referenced. The purpose of that assembly is to do type forwarding.</p> <h4>.NET Framework Application</h4> <p>Before .NET Core, thinks looked simpler. Typical .NET Framework minimal application loads following assemblies if no .NET Core libraries are referenced.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_0F5B5F37.png"><img title="image" style="margin:0px;display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_6F405279.png" width="226" height="70" /></a></p> <p>As you see, only two assemblies are loaded. Your application and  runtime assembly. If you take a look on such project in VS, you will notice much more assemblies. However they are not loaded if not used.</p> <p>.<strong>NET Core Application</strong></p> <p>Now, let’s take a look what happen if .NET Core application is loaded. In this case no <strong>mscorelib.dll</strong> is loaded, because it is not a part of .NET Core. But note, this time <strong>System.Runtime.Dll</strong> is loaded.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_7D129874.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_48060944.png" width="366" height="197" /></a></p> <p>.<strong>NET Core Application with reference to .NET Standard library</strong></p> <h1><strong></strong></h1> <p>In this case, I have same .NET Core application, which this time references a .NET Standard library. When started .NET Core application will  load one additional assembly <strong>StandardLibrary.dll</strong>.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_03C5A1F8.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_1197E7F3.png" width="349" height="194" /></a></p> <p>.<strong>NET Core Application with reference to .NET Standard library, which references .NET Framework assembly</strong></p> <p>In this example, I have created .NET Core application (NetCoreApp), which references .NET Core Library (NetCoreLib), which finally references a .NET Framework library (NetDesktopLib2). There is also .NET Framework Library (NetDesktopLib), which is referenced from application too.</p> <p>In this case, <strong>System.Rrntime</strong> is loaded from .NET Core and also <strong>mscorelib</strong> from .NET Framework.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_23747BC0.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_3146C1BB.png" width="367" height="291" /></a></p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1809067" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxASP.NET Core Issue: HTTP Error 502.5/blogs/damir_dobric/archive/2017/09/14/asp-net-core-issue-http-error-502-5.aspx2017-09-14T09:27:53Z2017-09-14T09:27:53Z<p>If you are deploying ASP.NET core 2.0 application to Azure App Service you might get following error:</p> <h5>HTTP Error 502.5 - Process Failure</h5> <h6>Common causes of this issue:</h6> <ul> <li>The application process failed to start </li> <li>The application process started but then stopped </li> <li>The application process started but failed to listen on the configured port</li> </ul> <p>As usual, first of all you have to do is don’t read the error message. The problem is that your AppService container already contains a version of .NET Core v1.* (or something else), which has deployed assemblies, which disturbs new deployment.</p> <p>Right now, this issue is related to migration from .NET Core 1 to .NET Core 2. But similar problem might happen in the future, due to some other reason.</p> <p>The solution for this problem is to delete the exisiting deployment manually. You might do this by connecting via FTP or by using of Kudu.</p> <p>If you want to connect to Kudu type following URL: <a title="https://iotservice-dev-002.scm.azurewebsites.de/DebugConsole" href="https://YOURSERVICENAME.scm.azurewebsites.de/DebugConsole">https://YOURSERVICENAME.scm.azurewebsites.de/DebugConsole</a></p> <p>After successfull connect, you will see following:</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_43A26A75.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_4A5573F8.png" width="724" height="372" /></a></p> <p>Then you can enter “dir” command to see the content of the root.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_65F9FFEE.png"><img title="image" style="display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_57BB86FE.png" width="910" height="353" /></a></p> <p>As next, navigate to following folder</p> <p>D:\home\site\wwwroot></p> <p>No you can delete all files with following command:</p> <p><strong>del *.*</strong></p> <p>After that you can deploy solution again.</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808995" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxHow about ‘mscorelib’ reference?/blogs/damir_dobric/archive/2017/08/25/how-about-mscorelib-reference.aspx2017-08-25T05:33:00Z2017-08-25T05:33:00Z<p>Sometimes, it is very difficult to understand what happen behind build process inside of complex solutions. You think you did all correct, and then you write simple line of, which is basically doing ‘nothing’ and then:</p> <p><font color="#ff0000"><em><strong>“</strong></em></font><a href="https://stackoverflow.com/questions/37468552/you-must-add-a-reference-to-assembly-mscorlib-version-4-0-0"><font color="#ff0000"><em><strong>You must add a reference to assembly mscorlib, version=4.0.0</strong></em></font></a><font color="#ff0000"><em><strong>”</strong></em></font></p> <p>It means you miss everything in framework. The problem is that you probably are targeting multiple frameworks. For example, I have a project with following targets:</p> <p>  <strong>  <TargetFrameworks>netstandard1.3;net46</TargetFrameworks></strong></p> <p>The error shown above is related to <strong>netstandard1.3</strong>. To fix this, you cannot simply go to project references and add reference to <strong>mscorelib</strong>.</p> <p>Rather, you should add a reference to following package:</p> <p><strong>Microsoft.NETCore.Portable.Compatibility</strong></p> <p>That will make your project compliable.</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808534" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxMicrosoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException/blogs/damir_dobric/archive/2017/08/23/microsoft-identitymodel-tokens-securitytokensignaturekeynotfoundexception.aspx2017-08-23T14:38:23Z2017-08-23T14:38:23Z<p>I guess, when you see error shown below (or similar) error, you might get kind of crazy:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <blockquote> <p>Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: 'IDX10501: Signature validation failed. Unable to match 'kid': 'VWVIc1WD1Tksbb301sasM5kOq5Q', <br /> token: '{"alg":"RS256","typ":"JWT","x5t"</p> </blockquote> </td> </tr> </table> <p>This error means that signature of the specified token cannot be validated. This happens if your token is issued by for example AAD in public cloud and you are validating signature against another cloud like german-cloud.</p> <p>In another words, the client has obtained the token from Authority1 and Service is validating signature by Authority2.</p> <p>AAD endpoint in configuration client and service must match.</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808516" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxUnable to resolve service type while injecting dependencies/blogs/damir_dobric/archive/2017/08/15/unable-to-resolve-service-type-while-injecting-dependencies.aspx2017-08-15T15:23:32Z2017-08-15T15:23:32Z<p>When implementing .NET Core dependency injection inside of ASP.NET Core or .NET Core. Assume you have implemented some class like 'IoTService.Config.GatewayConfig' and get following error on startup:</p> <table cellspacing="0" cellpadding="2"> <tr> <td>{"message":"Unable to resolve service for type 'IoTService.Config.GatewayConfig' while attempting to activate 'IoTService.GatewayHelper'.","type":"InvalidOperationException"}</td> </tr> </table> <p>This is how I have initialized injection:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p>services.Configure<GatewayConfig>(Configuration.GetSection("IotHubMap")); <br /> services.AddScoped<IGatewayHelper, GatewayHelper>(); <br /></p> </td> </tr> </table> <p>The error shown above will be thrown if the constructor shown in yellow is not implemented. Internal implementation is always looking for IOptions. The code shown below demonstrate hot to workaround this error and how to implement injectable class out of ASP.NET and need to implement IOptions interface.</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p>public class GatewayHelper : ISOmething <br />    { <br />         private GatewayConfig m_Cfg;</p> <p>       <font> public GatewayHelper(IOptions<GatewayConfig> options) : this(options.Value) <br />        {</font></p> <font></font> <p><font>        }</font></p> <p>        <br />        public GatewayHelper(GatewayConfig cfg) <br />         { <br />            this.m_Cfg = cfg; <br />        }</p> </td> </tr> </table><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808332" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxHow to find out Callback URI of the Windows 10 App?/blogs/damir_dobric/archive/2017/08/14/how-to-find-out-callback-uri-of-the-windows-10-app.aspx2017-08-14T05:20:00Z2017-08-14T05:20:00Z<p>Usually, when implementing AAD authentication in application, according to OAuth protocol, you will have to provide so called Callback-URI. This is the URL of the endpoint capable of receiving redirected request from authority.  Because the specification as originally written for web applications, this kind of URL is not natural for native apps.</p> <p>Depending on type of operative system or even better, depending on client library, which you use, this URL might look different. In a case of UWP (Universal Windows Application), the URL  can be extracte as follows:</p> <p>string URI = string.Format("ms-appx-web://Microsoft.AAD.BrokerPlugIn/{0}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpper());</p> <p>As a result you will get something like this:</p> <p><a title="ms-appx-web://Microsoft.AAD.BrokerPlugIn/S-1-15-2-1706387387-4189788551-2724562175-3977038930-2290055178-977454683-1391943604"><font>ms-appx-web://Microsoft.AAD.BrokerPlugIn</font>/S-1-XX-2-00000000-11111-22222-4444-2290055178-222222-1111111</a></p> <p>This URL is what you have to set in application blade in Azure AAD portal.</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808284" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxWhat is behind ‘404-error’ in Azure AD B2C?/blogs/damir_dobric/archive/2017/08/07/what-is-behind-404-error-in-azure-ad-b2c.aspx2017-08-07T05:35:00Z2017-08-07T05:35:00Z<p>AAD B2C is definitely an interesting approach to simplify dealing with various cloud identities. However, we should not forget, that working with security is always complex and can be very wired. In this post I will describe one example. </p> <p>Let’s assume, we want to perform a sign in operation from some application. In my case this is WPF application. It means it is running on Windows in .NET Desktop framework.</p> <p>To sign-in, I use following code, which use MSAL API:</p> <p class="MsoNormal" style="margin:0cm 0cm 0pt;line-height:normal;list-style-type:disc;mso-layout-grid-align:none;"><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;"><font style="font-size:9.5pt;"></font></span></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt;line-height:normal;list-style-type:disc;mso-layout-grid-align:none;"><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;"><font style="font-size:9.5pt;">var authResult = </font></span><font style="font-size:9.5pt;"><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">await</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;"> </span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">App</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">.<strong>PublicClientApp</strong>.<strong>AcquireTokenAsync</strong>(</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">App</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">.ApiScopes, GetUserByPolicy(</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">App</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">.PublicClientApp.Users, “<font>BLABLA</font>”</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">), </span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">UIBehavior</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">.SelectAccount, </span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">string</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">.Empty, </span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">null</span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">, </span><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;">App</span></font><span style="mso-bidi-font-family:consolas;mso-ansi-language:x-none;"><font style="font-size:9.5pt;">.Authority);</font></span></p> <font style="font-size:12pt;"></font> <p class="MsoNormal" style="margin:0cm 0cm 8pt;line-height:12pt;list-style-type:disc;"><span style="line-height:10pt;mso-bidi-font-family:consolas;mso-ansi-language:x-none;"><span style="mso-spacerun:yes;"><font style="font-size:9.5pt;"></font></span></span><span></span></p> <p class="MsoNormal" style="margin:0cm 0cm 8pt;line-height:12pt;list-style-type:disc;"><font style="font-size:12pt;"></font><font style="font-size:12pt;"></font> <table cellspacing="0" cellpadding="2"> <tr> <td></td> </tr> <tr> <td></td> </tr> </table> <table cellspacing="0" cellpadding="2"> <tr> <td> <p> This code will fail with following error, because the policy “BLABLA” does not exist.</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p><font color="#ff0000"><em>System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type Microsoft.Identity.Client.Internal.OAuth2.TokenResponse. Encountered unexpected character '<'. ---> System.Xml.XmlException: Encountered unexpected character '<'.</em></font></p> <p><font color="#ff0000"></font></p> <p>If you trace HTTP traffic, you will find more information behind this error:<span> <br /></span></p> <p><font color="#ff0000"><em><h2>404 - File or directory not found.</h2> <br />  <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3></em></font></p> </td> <td></td> </tr> <tr> <td></td> <td></td> </tr> </table> </td> </tr> </table> </p> <p>This means, that error 404 will happen if you specify the policy which does not exist, at least. </p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1808132" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxDesktopAppConverter error : qualified file name must be less than 260/blogs/damir_dobric/archive/2017/07/22/desktopappconverter-error-qualified-file-name-must-be-less-than-260.aspx2017-07-22T12:53:00Z2017-07-22T12:53:00Z<p>When working with Desktop Converter, you might get following error: </p> <p><font color="#ff0000">C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.0.2.0_x64__8wekyb3d8bbwe\DesktopAppConverter.ps1 : The <br /> specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and <br /> the directory name must be less than 248 characters. <br /> At line:1 char:1 <br /> + &'C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.0.2.0_ ... <br /> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <br />    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException <br />    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DesktopAppConverter.ps1</font></p> <p>This error has nothing to do with the length f any of your application files. The problem is destination argument of following command:</p> <p>> DesktopAppConverter.exe -Installer <font>C:\Temp\NodejsApp\NodejsApp</font> -AppExecutable node.exe -Destinat <br /> ion <font>C:\Temp\NodejsApp\NodejsApp\packages</font> -PackageName "MyNodeApp" -Publisher "CN=MyPublisher" -Version 0.0.0.1</p> <p>This command creates the package from application in path ‘<font>C:\Temp\NodejsApp\NodejsApp</font> ’ and will try to store it to path <font>C:\Temp\NodejsApp\NodejsApp\packages</font> .</p> <p>Because creating process will read specified path, but in the same time will create packages under the reading path, it will recursively grow until it crashes.</p> <p>Solution is very easy. You should create a package out of application root:</p> DesktopAppConverter.exe -Installer <font><font>C:\Temp\NodejsApp\</font>NodejsApp</font> -AppExecutable node.exe -Destinat <br /> ion <font><font>C:\Temp\NodejsApp</font>\packages</font> -PackageName "MyNodeApp" -Publisher "CN=MyPublisher" -Version 0.0.0.1<div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1807798" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxHow to access log files on Windows IoT Core device?/blogs/damir_dobric/archive/2017/07/20/how-to-access-log-files-on-windows-iot-core-device.aspx2017-07-20T09:36:50Z2017-07-20T09:36:50Z <p>Sometimes, when running on Windows IoT Core device, you might have some issues when trying to access files in LocalAppData folder.As you see there is no any file shown in dashboard. But, believe me, there are files in the folder.</p> <p><a href="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_48E0D625.png"><img title="image" style="border:0px currentcolor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" border="0" alt="image" src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/damir_5F00_dobric/image_5F00_thumb_5F00_3DB74BDB.png" width="732" height="258" /></a></p> <p>Interestingly, when this happen, you will be able to access files via PowerShell. Following power-shell command shows how to fo that.</p> <p>[192.168.0.123]: <br />cd C:\Data\Users\DefaultAccount\AppData\local\Packages\20c45e87-953a-4d99-919b-c6ee7e9642d3_h95tnwbrnsgam\LocalState</p><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1807755" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspxConfiguring Application Configuration in ASP.NET Core 2/blogs/damir_dobric/archive/2017/07/16/configuring-application-configuration-in-asp-net-core-2.aspx2017-07-16T08:16:44Z2017-07-16T08:16:44Z<p>Configuration of asp.net core seems to be particularly moved from startup.cs in program.cs. Here is one example:</p> <table cellspacing="0" cellpadding="2"> <tr> <td> <p class="MsoNormal" style="margin:0in 0in 8pt;line-height:12pt;list-style-type:disc;"><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff"><font style="font-size:9.5pt;">public</font></font></span><font style="font-size:9.5pt;"><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">class</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#2b91af">Program</font></span></font></font><font style="font-size:9.5pt;"><span style="line-height:10pt;mso-bidi-font-family:consolas;"> <br /><font face="Consolas"><span style="mso-spacerun:yes;">    </span>{ <br /><span style="mso-spacerun:yes;">        </span></font></span><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">public</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">static</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">void</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> Main(</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">string</font></span></font><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;">[] args) <br /><span style="mso-spacerun:yes;">        </span>{ <br /><span style="mso-spacerun:yes;">            </span>BuildWebHost(args).Run(); <br /><span style="mso-spacerun:yes;">        </span>} <br /> <br /><span style="mso-spacerun:yes;">        </span></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">public</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">static</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#2b91af">IWebHost</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"> BuildWebHost(</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">string</font></span></font><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;">[] args) => <br /><span style="mso-spacerun:yes;">            </span></span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#2b91af">WebHost</font></span></font><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;">.CreateDefaultBuilder(args) <br /><span style="mso-spacerun:yes;">            </span>.ConfigureAppConfiguration((ctx, cfgBuilder) => <br /><span style="mso-spacerun:yes;">            </span>{ <br /><span style="mso-spacerun:yes;">                </span>cfgBuilder. <br /><span style="mso-spacerun:yes;">                 </span>AddJsonFile(</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#a31515">"appsettings.json"</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;">, optional: </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">false</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;">, reloadOnChange: </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">true</font></span></font><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;">) <br /><span style="mso-spacerun:yes;">                </span>.AddJsonFile(</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#a31515">$"appsettings.</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;">{ctx.HostingEnvironment.EnvironmentName}</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#a31515">.json"</font></span><span style="line-height:10pt;mso-bidi-font-family:consolas;">,  <br />                 optional: </span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#0000ff">true</font></span></font><font face="Consolas"><span style="line-height:10pt;mso-bidi-font-family:consolas;">) <br /><span style="mso-spacerun:yes;">                </span>.AddEnvironmentVariables(); <br /><span style="mso-spacerun:yes;">            </span>}) <br /><span style="mso-spacerun:yes;">                </span>.UseStartup<</span><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font color="#2b91af">Startup</font></span></font></font><span style="line-height:10pt;mso-bidi-font-family:consolas;"><font face="Consolas"><font style="font-size:9.5pt;">>() <br /><span style="mso-spacerun:yes;">                </span>.Build(); <br /><span style="mso-spacerun:yes;">    </span>}</font></font></span> <br style="mso-special-character:line-break;" /> <br style="mso-special-character:line-break;" /></p> </td> </tr> </table><div style="clear:both;"></div><img src="http://developers.de/aggbug.aspx?PostID=1807676" width="1" height="1">ddobrichttp://developers.de/members/ddobric/default.aspx