Archive

Archive for the ‘.NET’ Category

Differences in browsers engines under AngularJS

Working to updates on a AngularJS site, i discovered subtle differences.
I don’t know if there were these problems before, but certainly they raised while testing with Angular 1.6.5
First, if the user was switching the site language from English to Italian while working , saving a date Moment was not able to parse the date giving “Invalid date” using the latest Chrome and Firefox, while with Ie11 and Edge all ok.
In origin the code was (oh yeah, it uses the DOM objects instead of the binding..)

var testDate = moment($("#txtBirthDate").val()).format($scope.DateFormat.toUpperCase());
if (testDate === "Invalid date") {
    logWarning(localize.localizeText("DateNotValid"), null, true);
    $("#txtBirthDate").focus();
    return false;
}

For the first thing , using Visual Studio 2017 and starting the project i noticed that finally the breakpoints in javascript code are working also under Chrome, great thing:

Obvious , $scope.DateFormat.toUpperCase() is evaluated at runtime as YYYY-MM-DD for English and DD/MM/YYYY for Italian.
In order to work also with Chrome and Firefox this is the correct Moment syntax:

var testDate = moment($("#txtBirthDate").val(), $scope.DateFormat.toUpperCase()).format($scope.DateFormat.toUpperCase());

This code instead works without changes in all browsers:

var datBirthDate = moment($("#txtBirthDate").val(), $scope.DateFormat.toUpperCase()).toDate();
var BirthDate = datBirthDate.yyyymmdd();  // as requested for SQL Server

Then the other issue, an awkward issue.
The customers have the bad habit to press F5 or worse the browser refresh button in the pages, that in Angular does little sense.
In the site the other controllers (the ones not relatives to the home page) are loaded with ocLazyLoad (current version v1.0.10), in config.route.js the code was

}, {
    url: '/phones',
    config: {
        title: 'Phones',
        role: 'Administrator;PowerUser;User',
        templateUrl: 'app/tabelle/phones.html', 
        resolve: requireDependencies(['app/services/datacontextphones.js'], ['app/tabelle/phones.js']]),
        settings: {
            content: '<i class="fa fa-mobile"></i> {placeholder}',
            nav: 3,
            localizeKey: 'mnuPhones',
            minicontent: '<i class="fa fa-mobile" title="{placeholder}"></i>'
        }
    }
}, {

The function:

function requireDependencies(depContext, depMain) {
    return {
        resolvedData: ['$q', '$rootScope', '$ocLazyLoad', function ($q, $rootScope, $ocLazyLoad) {
            $ocLazyLoad.load(depContext);
            $ocLazyLoad.load(depMain);
        }]
    };
}

and this code with Ie11 and Edge was working fine, the users could hit F5, the browser refresh button, and the page is refreshed without problems.
Instead with Chrome and Firefox:

After some struggle, the working code in config.route.is that doesn’t use the function requireDependencies and all pages are surviving to the refresh in all browsers:

}, {
    url: '/phones',
    config: {
        title: 'Phones',
        role: 'Administrator;PowerUser;User',
        templateUrl: 'app/tabelle/phones.html', 
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load({
                    name: "phones",
                    files: [
                        'app/services/datacontextphones.js',
                        'app/tabelle/phones.js'
                    ]
                });
            }]
        },
        settings: {
            content: '<i class="fa fa-mobile"></i> {placeholder}',
            nav: 3,
            localizeKey: 'mnuPhones',
            minicontent: '<i class="fa fa-mobile" title="{placeholder}"></i>'
        }
    }
}, {

Advertisements
Categories: .NET, Angular, Javascript, Vs2017

Dump a .NET DataTable in VB.NET as XML file


If we have a DataTable named rstData in our VB.NET code:

Dim ds As New DataSet
ds.Tables.Add(rstData)
ds.Tables(0).TableName = "ATableNameYouWant"
ds.WriteXml("e:\MyTableDump.xml")

Categories: .NET, VB.NET

Not only my sites..

5-15-2017 11-49-43 PM

Categories: .NET

Sys.WebForms.PageRequestManagerServerErrorException

Followed by:Object reference not set to an instance of an object.
I was struggling in an old Asp.Net site, which is using Microsoft Ajax Toolkit, with this error.

In order to reduce the postbacks i used some jquery for partial page updates, and using a simple html select with a button for change the parameter to a REST call, i got this error.
The problem solution is very simple.. the HTML button tag by default causes a postback, and the error was caused from a null value in the Page_Load event of the behind code: the button type must be “button”, otherwise without specifying the type is considered as “submit”.

Then the HTML is:

<button id="cmdUpdateByFilter" onclick="updateSint();" type="button" class="Botton">Update</button>

Categories: .NET, Ajax, HTML5, VB.NET

Visual Studio 2015 Performance Profiler metabase error

Starting the Performance Profiler in order to analyze a web site i got the error “The website metabase contains unexpected information or you do not have permission to access the metabase ….”:

The solution is configured to run using the local IIS (of Windows 10).
In order to fix this problem on the Control Panel->Programs and in “Turn Windows features on or off”

must be activated the Windows Authentication

and the entire IIS6 Management Compatibility branch

Categories: .NET, Vs2015

Roslyn access denied error

Publishing a .NET 4.5 site on a normal provider, not Azure, i got the yellow screen of death “Access is denied” with “Cannot execute a program. The command being executed was \roslyn\csc.exe”.
Since the .NET 4.5 , Roslyn is the default compiler; Roslyn is interesting (even if i wrote code that was evaluating C# code years ago using Reflection) but i was in a hurry, i was needing to make the site working ASAP.
The quick & dirty solution is to delete from web.config the system.codedom section.

Categories: .NET, Vs2015

Vb6 software on Azure VM

There are still customers that uses old, aged software: for example, i have customers using my old program for truck transports, that uses a Microsoft Access file as database.
As i wrote in this post, this software in installed on a on-premise server, which was tipically Windows server 2003.
Now, these old servers (often recycled) are dying, the hardware today is more cheaper than in the past but an Windows Server 2012 license is still expensive for a small office.
So the idea: let’s try to migrate to Azure!
So i began an incredible amount of try & catch (errors..)
The application requires to send emails via CDO , with an attached pdf file generated from the Crystal Reports engine (used from the app for the printing activities).
In order to print via CDO is required a working email client; in the old Windows 2003 there was by default Outlook Express, instead from 2008 version in Windows Server there is no more an email client: this can be resolved installing Windows Mail, but it requires .NET 3.5
First error: using an Windows Server 2012 DataCenter NOT R2.
The main problem with the “normal” version is, IMHE (In My Humble Experience) that .NET 3.5 is not installable because you can’t use the downloadable 3.5 installer and this must be done from the Server Manager that complains about missing sources (for example see here, but i was not able to achieve the same result) : could be that attaching an ISO file (of Windows Server 2012) it works.
But i lose no more time and try creating instead an Windows Server 2012 R2 vm: same complain about the missing sources, but this time .NET 3.5 installed without issues.
The installation of Windows Mail was without problems and so for my app.
The only problem is the calendar for date input: my vb6 app uses mscal.ocx (perhaps a wrong choice) which is problematic.
For example in the setup.lst file generated from the vb6 package installer wizard the mscal is generated as

File10=@MSCAL.OCX,$(WinSysPath),$(DLLSelfRegisterEx),$(Shared),5/7/98 12:00:00 AM,90112,8.0.0.5007

But the DLLSelfRegisterEx must be changed in DLLSelfRegister otherwise the setup is not successful.
And in every case the problem is that the calendar was not displayed (interface in Italian):


The solution was to recreate from scratch the VM and create an vb6 installer WITHOUT mscal.ocx: it is already present in the Azure vm and trying to install another mscal.ocx causes big troubles in the registry; now the mscal.ocx is working ok.
Another curious thing was that in the vb6 code

With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = boolUseSsl
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = intSmtpAuth
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUser
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPwd
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmtpSvr
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = intSendUsing
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = intSvrPort
    .Update
End With

“microsoft” was accidentally written with the initial “m” uppercase, so the email sending was not working in the new 2012 R2 server (instead in Windows Server 2003 yes!); after the correction, emails sent.

Firefox needs UTF8 for GeoXml3


I’m developing an WebAPI2 solution with Angular that receives, from Android devices, GPS points.
So Latitude , Longitude , Speed etc. are saved in a SQL Server 2014 table; from the web site the headquarter would follow the real time navigation.
The chosen approach was to write an KML file from the db data, and show this KML in a GoogleMaps window.
Having local files (not on another domain) the best solution is to use the GeoXml3 library, which is relatively easy to use (examples here and here).
For the javascript part, no problem: there is an simple setTimeout that calls via jQuery an WebAPI2 method that re-write the kml (the name is the record ID), and then adding an random number to the querystring the boss can follow the persons wandering somewhere, seeing the kml line that slowly progress on the map.
But there was an problem: On IE10 , 11, Chrome, Edge all ok; instead on Firefox (Windows or Ubuntu or Android tablet) no kml shown.
Sometimes the things are discovered in a very casual manner…i tried to save the KML with another name using Notepad++ , and change the code in order to not use the API call and instead try to show immediately this second file where i wanted to test some change, in order to understand what was wrong : bingo, KML immediately visible!
This was a real head scratching…the files (the generated from the system, and the one saved from the previous) in Notepad++ was absolutely the same, no visible difference.
So i tried to compare them with WinMerge and surprise, the generated file was full of strange characters before every normal character, immediately i realized “oops, the encoding?” and only after i noticed in Notepad++ that in the Encoding menu the file saved from Notepad++ itself was UTF8 encoded, and the one produced from the C# code was without encoding.
In the WebAPI2 method effectively i used Unicode: so now, all the browsers shows the KML writing the file as:

private async Task WriteTextAsync(string filePath, string text)
{
    //byte[] encodedText = Encoding.Unicode.GetBytes(text);
    byte[] encodedText = Encoding.UTF8.GetBytes(text);
    //
    using (FileStream sourceStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.None, bufferSize: 1048576, useAsync: true))
    {
        await sourceStream.WriteAsync(encodedText, 0, encodedText.Length);
    };
}

Error creating an Azure Cloud Service with 2.7 SDK

From some days is available the Azure 2.7 SDK, and i’m trying it with Visual Studio 2013: when Visual Studio was alerting that were available this update i installed it from inside Visual Studio.
Creating an Azure Cloud Service i got the error “Microsoft Azure Tools: Error: The installed Microsoft Azure Compute Emulator does not support the role binaries. Please install the latest Microsoft Azure Compute Emulator and try again.”.
I don’t know if is the real solution valid for all the cases, but anyway re-downloading the Microsoft Azure SDK for .NET – 2.7  from http://www.microsoft.com/en-us/download/details.aspx?id=48178 but installing only the MicrosoftAzureComputeEmulator-x64.exe (x86 if you are using an 32 bit environment, but who has today an 32 bit pc?) finally the project has started.

Categories: .NET, Azure, Vs2013