Thursday, October 1, 2020

Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (83)

 This is an easy solution, you need to recompile SAAS using:

npm rebuild node-sass



Wednesday, August 5, 2020

Android emulator not recognizing localhost

While configuring Google as an authentication provider for a react native app, I had to configure the redirect uri, which usually points to localhost.

However, the android emulator could not figure out the redirect uri, and that's because the android emulator and my PC are in different networks. localhost works on my PC, but the android emulator is its own network. The way to fix it is with adb reverse. Like this:

adb reverse tcp:44371 tcp:44371

The port number does not necessarily need to match, it can be different. The first port is the emulator's, and the second port is obviously your PC.

Saturday, July 18, 2020

Connecting to IIS Express from an Android emulator

I've been struggling with this. While working on a proof of concept of an Android app connecting to an API running in my localhost, the Android app could not to IIS Express. At first, I thought it had to do with using a self-signed certificate. But even without SSL I still got a network error. This is how I fixed it:

1) First, the Android app should connect to the local ipv4 address, not localhost, not 127.0.0.1

2) Modify the file applicationhost.config as indicated here https://blogs.blackmarble.co.uk/rfennell/2012/11/06/using-iisexpress-for-addresses-other-than-localhost/, by replacing localhost with *

3) Restart IIS Express

And that's it!




Thursday, July 16, 2020

Installing yarn on Debian - No such file or directory: 'global'

This was happening while trying to install the ignite bowser demo app (https://github.com/infinitered/ignite).

The final solution was to run the following to fix the problem:

sudo apt remove cmdtest 

sudo apt install yarn

Which I found here (https://github.com/yarnpkg/yarn/issues/3708)

Wednesday, July 15, 2020

Accessing WSL files from Windows

I've been playing with WSL2 and accessing the Linux files is quite easy as indicated here https://superuser.com/questions/1110974/how-to-access-linux-ubuntu-files-from-windows-10-wsl. You only need to fire up File Explorer and type \\wsl$\Ubuntu\home\<<username>>

Of course, you need to replace <<username>> with your actual username.

Thursday, July 9, 2020

Copying files ignoring errors on Windows

When copying a directory between Linux and Windows a lot of errors might be thrown, so I like to use this command to silent and ignore the errors:

xcopy $SOURCE $DESTINATION /C /E /Q 

Wednesday, July 8, 2020

Talks 2 Code Conference

 Check out my talk for the magazine Software Guru. It's in Spanish though.


https://youtu.be/DyotAYEa5AU



Wednesday, July 1, 2020

WslRegisterDistribution failed with error: 0xffffffff

While setting up WSL2 I came across this error. This seems like a scary error "WslRegisterDistribution failed with error: 0xffffffff", but all it means is port 53 is taken. 

The solution for me was to run this in cmd:
netstat -aon | findstr ":53"

And then find the PID that was using port 53, go to the task manager and kill it.

I also stopped the Docker services just in case (in the Windows "Services" UI).

Friday, June 26, 2020

React native error: EPERM: operation not permitted, lstat signing-config.json

So I started working with React native. While setting up a project in Visual Studio Code, this error came up. What ended up fixing the error is deleting the file "android/app/build/intermediates/signing_config/debug/out/signing-config.json".

Monday, May 25, 2020

Bind a list of non-sequential indexes

I recently discovered a bug in an application. There was a list of items in a form, each with an index (0, 1, 2, 3...) and if I removed item 2 only items 0 and 1 would get posted.

This seemed to me a rather common problem and something more people would have encountered by now. Luckily, I came across this post from 2008 by Phil Haack (https://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/) in which he basically says we need a hidden input with the Index suffix for each item we need to bind to the list.

And guess what? It works!!

Saturday, April 18, 2020

Upgrade to .NET Core 3.1 - Could not load file or assembly Microsoft.IntelliTrace.Core

The last error I came across was this one, "Could not load file or assembly Microsoft.IntelliTrace.Core". This happened while debugging a test.

The initial fix was upgrading the referenced nuget packages to their latest version. However, after this, I still got the error. The solution was to update Visual Studio 2019 to it's latest version. Not very intuitive, but it worked.

Friday, April 17, 2020

Upgrade to .NET Core 3.1 - Using StructureMap in .NET 3.1

In short, you should stop using StructureMap. It's no longer supported. Instead, use Lamar, and only have to make minimal changes. It's written by the same guy who wrote StructureMap.

In your Program.cs:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseLamar()
                .ConfigureWebHostDefaults(webBuilder =>
                {

In your Startup.cs:

        public void ConfigureContainer(ServiceRegistry services)
        {
             ...
services.Scan(scan =>
             {
...

Wednesday, April 15, 2020

Upgrade to .NET Core 3.1 - Could not find an IRouter associated with the ActionContext. If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection and use it to create a UrlHelper

The error itself exposes the solution. You need to stop using: 

            return new UrlHelper(helper.ViewContext).DisplayLink(action, linkText, returnLink);

And instead use (notice I'm not using DI, but you should use DI to retrieve IUrlHelperFactory):

            var urlHelperFactory = ServiceLocator.Current.GetInstance<IUrlHelperFactory>();
            return urlHelperFactory.GetUrlHelper(helper.ViewContext).DisplayLink(action, linkText, returnLink);

Tuesday, April 14, 2020

Upgrade to .NET Core 3.1 - Migration warning CS0618 'RazorViewAttribute' is obsolete

This error is simple, you can even find the answer is SO. It's caused by one of your nugets, you only need to update it to the latest version. Finding the offending nuget is another story. Hopefully you don't have too many nugets to update.

Sunday, April 12, 2020

Upgrade to .NET Core 3.1

Last week I had the task of upgrading a project written in .NET Core 2.1 to .NET Core 3.1. I'll be posting solutions to the errors I came across. But first, I'll show important sections of my Startup.cs and Program.cs:

I'll start with Program.cs:


        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            host.Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseLamar()
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                }).ConfigureLogging(builder =>
                {                    
                    ...

                    builder.AddApplicationInsights();

                });

On to the file Startup.cs

    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureContainer(ServiceRegistry services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
...
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Con

            services.AddMediatR();
            services.AddAutoMapper();
            services.AddSession();

...
            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();

                options.Filters.Add(typeof(AzureAuthorizationFilter));
...
                options.UseModelBinding();
            });
            services.AddRazorPages().SetCompatibilityVersion(CompatibilityVersion.Latest).AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
                .AddTypedRouting()
                .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
            services.AddAuthorization();
            services.Configure<RazorViewEngineOptions>(options => {      
...
            });

            services.AddSignalR();

            services.Scan(scan =>
            {
                scan.TheCallingAssembly();
...
                scan.WithDefaultConventions();
            });
            services.For<IPrincipal>().Use(x => Thread.CurrentPrincipal);
...
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();
            app.UseSession();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapHub<NotificationHub>("/pushHub");
            });
        }

    }