Publish an ASP.NET website without roslyn folder

If you create a ASP.ENT website using Visual Studio 2015 or higher and .NET Framework 4.5.2, it by default uses Roslyn which is a set of open-source compilers and code analysis APIs for C# and Visual Basic. Publishing this would also include “roslyn” folder in bin directory containing a bunch of libraries and exe files which creates issues if you are using a shared hosting service as normally shared hosting do not run under full trust. We can simply remove this by going to Tools -> NuGet Package Manager -> Manager NuGet Packages for Solution -> Uninstall following packages Microsoft.CodeDom.Providers.DotNetCompilerPlatform Microsoft.Net.Compilers Check web.config and make sure the following section was removed by the NuGet package uninstall. If it did not get removed for any reason, then clean it up manually <system.codedom> <compilers> <compiler language=”c#;cs;csharp” extension=”.cs” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ warningLevel=”4″ compilerOptions=”/langversion:6 /nowarn:1659;1699;1701″/> <compiler language=”vb;vbs;visualbasic;vbscript” extension=”.vb” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ warningLevel=”4″ compilerOptions=”/langversion:14[…]

Phaser RESIZE Scale mode not resizing the game on mobile

I had minimal html markup for a web game which used RESIZE scale mode as following <!DOCTYPE html> <html> <head> <meta charset=”utf-8″ /> <title>My Game</title> <meta http-equiv=”Content-type” content=”text/html; charset=utf-8″> <meta name=”viewport” content=”width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no”> <link rel=”stylesheet” href=”css/app.css”> <script src=”js/phaser.min.js”></script> </head> <body> <div id=”game-container”> <div id=”mygame”></div> </div> <script src=”js/game.js”></script> </body> </html> The game was started with the following statement var mygame; window.onload = function () { mygame = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, “mygame”); mygame.state.add(“Boot”, Boot); mygame.state.add(“Loading”, Loading); mygame.state.add(“TheGame”, TheGame); mygame.state.start(“Boot”); } code of Boot class // —————boot——————— var Boot = { init: function () { mygame.scale.scaleMode = Phaser.ScaleManager.RESIZE; }, preload: function () { mygame.stage.backgroundColor = 0x510100; mygame.load.image(“loading”, “images/loading.png”); }, create: function () { mygame.state.start(“Loading”); } }; When the game was loaded initially on mobile, it took the available space on the mobile screen for that orientation but turning the mobile device to other orientation did not correctly fit in the[…]

Force Windows Store App to Full Screen Mode

In order to launch windows store app to full screen mode, check out the code here. Once app is launched in full screen mode, it can be resized by user by using the resize option which is available in all app windows and can not be removed. For windows pc, we can capture window resize event and try to enter full screen again which in effect doesn’t let user resize the application window. The java script code for achieving this: var page = WinJS.UI.Pages.define(“/index.html”, { ready: function (element, options) { // Add event for window resize event window.addEventListener(“resize”, onResizeView); } }); function onResizeView() { // Whenever window is resized, enter it to full screen mode var ViewManagement = Windows.UI.ViewManagement; var ApplicationView = ViewManagement.ApplicationView; var view = ApplicationView.getForCurrentView(); view.tryEnterFullScreenMode(); }  

Launch External Url in Browser from Windows Store App

The java script code for achieving this: // Create a Uri object from a URI string var uri = new Windows.Foundation.Uri(“http://test.com”); var options = new Windows.System.LauncherOptions(); // Launch the URI with a warning prompt options.treatAsUntrusted = true; // Launch the URI Windows.System.Launcher.launchUriAsync(uri, options).then( function (success) { if (success) { // URI launched } else { // URI launch failed } });  

Quick Tip

Convert C# Object to JSON and create object from JSON string

Json.Net is the preferred way to go about it because of performance gain it gets compared to JavascriptSerializer. Download and install Newtonsoft.Json using Nuget Now in order to create Json for an object simply use SerializeObject method as following Product product = new Product(); product.Name = “Apple”; product.Expiry = new DateTime(2008, 12, 28); product.Sizes = new string[] { “Small” }; string json = JsonConvert.SerializeObject(product); // { // “Name”: “Apple”, // “Expiry”: “2008-12-28T00:00:00”, // “Sizes”: [ // “Small” // ] // } In order to convert Json to the object use DeserializeObject method as following string json = @”{ ‘Name’: ‘Bad Boys’, ‘ReleaseDate’: ‘1995-4-7T00:00:00’, ‘Genres’: [ ‘Action’, ‘Comedy’ ] }”; Movie m = JsonConvert.DeserializeObject<Movie>(json); string name = m.Name; // Bad Boys  

Windows 10 App :Host Defined Policy: Inline Script. Resource will be blocked.

I recently ported one of my java script projects to Windows store app and got the error as following CSP14321: Resource violated directive ‘script-src ms-appx: ‘unsafe-eval’ blob:’ in Host Defined Policy: inline script, in ms-appx://13bdc914-5111-4c95-a5e6-82029c5105ec/index.html at line 21 column 12. Resource will be blocked. If you have something like the following, it won’t work <a href=”javascript:void(0)” id=”somelink” onclick=”callMethod();”>Link</a> Since I was using jQuery in the project, I simply used jQuery to bind click event to the element $(“#somelink”).click(function () { callMethod(); }); and Voila, everything works but I had many pages which had this reference and I had to make this change to all pages. After some research I found that there is an alternate way which is much faster to change. By default ms-appx:/// protocol is used in store apps to fetch the content. For web apps specify a specific protocal ms-appx-web which is then used for the app. This can be done[…]

Quick Tip

Tip of the day: Blank href in html A link

When you are using <a> link and want to bind it with onclick event in stead of href location, it can be set to # as following <a href=”#” onclick=”javascript:callMethod();”>Link</a> As you know setting href to “#some_id” is an approach used to link content inside the page so if you are using above approach, it will make the page jump to top which is not an elegant solution. There is an alternate way which is much better as it does not make page jump. <a href=”javascript:void(0)” onclick=”javascrit:callMethod();”>Link</a> Simple and elegant..  

Error: An invalid APK was received. Not a signed jar file.

When I tried to upload APK file to Aptoide store which was built using cordova and signed for the release version, I got this error An invalid APK was received, does not seem to have all files correctly signed. Please verify apk signature and try again. Signature error: Not a signed jar file The same APK was fine when uploaded on Google Play Store. In order to fix this problem I had to create an unsigned release version of the APK using cordova and then sign it using jarsigner utility. In order to create unsigned release version of the APK, following command can be used cordova build android –release Jarsigner utility comes with java sdk and can be found @ your JDK bin folder (for ex, C:\Program Files\Java\jdk1.8.0_131\bin). The command which can be used to sign the APK is as following jarsigner -verbose -tsa http://timestamp.comodoca.com -keystore android.keystore -storepass password mygame.apk alias[…]

How to avoid screen flicker when embedding responsive Phaser game in Bootstrap site

Phaser games can be responsive and will fit in the available space which makes it easy to embed in variety of devices with different sizes. When Phaser games are embeded in a Bootstrap site which is responsive, there can be some flickering on the web page when game is initially loaded. When Phaser games are loaded, it loads in the actual size it was created in and afterwards CANVAS is resized to fit in the available space. The example below is a bootstrap template in which Phaser game is embeded in half of the screen and remaining half screen has some other content. Click the link to load the page to see how the game is being resized to fit in the available space. To make the game load in a nice manner without visible resizing, we need to intially hide the div in which game is loaded. In Phaser boot method we can[…]