Matblazor throws an exception in my WebAssembly project in .NET 6 - .net-6.0

I have used Matblazor succesfully in a .Net blazor server project in .NET 5.
But my new project is now a Webassembly and is running on .NET 6.
I followed all the instructions in the Matblazor home page site, but I have this client side error:
Could not find matBlazor.matButton.init (matbalzor was undefined)

you should modify your program.cs like this
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using WareHoseManagement.Client;//this is my application so you should write here yours
using MatBlazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddMatBlazor();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();

Related

Passing values from native project to shared project Xamarin

Im currently facing an issue with using a 3rd party authenticator for my xamarin forms app. The code to execute has to be done natively in the platform project. The issue im facing is how to get the information(successful login, token, email etc) from the ios/android native project to the shared project for me to access it and continue the application. Below is an example of how the code looks below in the ios native project.
var client = new Auth0Client(new Auth0ClientOptions
{
Domain = "example.us.auth0.com",
ClientId = "123456789"
});
var loginResult = await client.LoginAsync();

Detected a connection attempt to an ASP.NET SignalR Server

I have a vuejs application that is created in vue-cli3 and ASP.Net WebAPI w/SignalR created in .Net Framework 4.6.x
I'm having an issue connecting to SignalR and it's throwing an error "Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server".
As per this link: Detected a connection attempt error, i should use signalR instead of #aspnet/signalr. But when i try to use it, now it throws a jquery reference error. Should i really use Jquery here? I'm already stuck for 2 days on this.
My Vue Component:
import { HubConnectionBuilder, LogLevel } from 'signalr'
// import { HubConnectionBuilder, LogLevel } from '#aspnet/signalr' <--- I already tried this,same error
created() {
const connection = new HubConnectionBuilder()
.withUrl('https://localhost:44356/chat-hub')
.configureLogging(LogLevel.Information)
.build()
connection.start()
}
My Startup.cs
public void Configuration(IAppBuilder app)
{
app.Map("/chat-hub",
x =>
{
x.UseCors(CorsOptions.AllowAll);
var hubConfig = new HubConfiguration
{
};
x.RunSignalR(hubConfig);
}
);
app.MapSignalR();
}
The problem is that you have used the ASP.NET Server component and the .NET Core Client.
You cannot mix those as they are not compatible.
Since you are building on .Net Framework 4.6.x and have the ASP.NET Server you need to download the ASP.NET Client which yes, does require JQuery.
If you don't want to use JQuery you will need to do the opposite and replace your server component with .NET Core 3.1 and keep (update) to the same .NET Core Client. Be aware that this is not a simple replacement, you will need to update many aspects of your code.

Connecting to Event Hub

In my code below I am attempting to create a producer client that i can use to send events to a Event Hub. I am getting a System.PlatformNotSupportedException: 'The WebSocket protocol is not supported on this platform. error Any guidance on how i can resolve this would be much appreciated. FYI my platform is Windows 7, although this program is intended to run on a windows 2008 server or later.
var producerOptions = new EventHubProducerClientOptions
{
ConnectionOptions = new EventHubConnectionOptions
{
TransportType = EventHubsTransportType.AmqpWebSockets,
},
RetryOptions = new EventHubsRetryOptions
{
MaximumRetries = 5,
TryTimeout = TimeSpan.FromMinutes(1)
}
};
var producer = new EventHubProducerClient(connectionString, eventHubName, producerOptions);
//here is where the error occurs. which is inside a try - catch block
var eventBatch = await producer.CreateBatchAsync();
......
The Event Hubs client library relies on the underlying framework for its transport communication. In this case, it sounds as if you're using the full .NET Framework on Windows 7, where web sockets is not supported.
So long as your aren't using a UWP application, changing the target framework to .NET Core and using the netstandard2.0 target from the client library may work. (see: this PR)
More detail can be found in the accepted answer for this question, which also contains some advice for third party packages that may work as a polyfill.

How can I deploy a Blazor server-hosted application from Visual Studio 2019

I am using VS2019 Preview.
I have created a "server-hosted" Blazor application using the latest Blazor extension (16.0.19227). This is the variant that contains 3 separate projects...
MyApp.Client
MyApp.Server
MyApp.Shared
I can debug this by making MyApp.Server the active project and all works fine but I'm struggling to publish/deploy this to Azure. I have tried the following...
Right-click on MyApp.Server in Solution-Explorer
Choose "Publish"
Go through the wizard to create a new publish profile
Change the deployment mode to "self-contained"
Hit publish
At this point I get an error during deployment...
CSC(0,0): Error CS0006: Metadata file 'D:\work\Applications\Web\MyApp.Client\bin\Release\netstandard2.0\win-x86\MyApp.Client.dll'
could not be found
This appears to be because the "Target Runtime" in the web-deploy profile is set to win-x86. The client application is actually being built as
"D:\work\Applications\Web\MyApp.Client\bin\Release\netstandard2.0\MyApp.Client.dll"
(without the additional win-x86 subfolder) so the deployment process seems to be making an incorrect assumption about the paths used by the build process. There's no way in the publish dialog to specify a blank/don't care target runtime.
Is there a workaround for this or perhaps I am using the wrong approach for deployment?
There is some official documentation but it's not very helpful.
Update It seems that the deployment is using the output path of the Client project and then just appending netstandard2.0{Target Runtime} to it so changing the output path in the Client project is not enough to work around the issue.
Update 2 Removing the RuntimeIdentifier tag in the publish profile by editing the xml simply results in deploy-time error stating that an empty RuntimeIdentifier is incompatible with a self-contained deployment. Unfortunately the self-contained deployment is necessary because Azure does not yet host .net core 3 directly.
because Azure does not yet host .net core 3 directly.
But it does.
In the Azure Portal, go to your WebApp after deployment (or create one beforehand).
Go to Extensions and click Add [+] and select ASP.NET Core 3 (x86 for the free hosting).
Also go to Settings, General and enable WebSockets, they're Off by default.
Temporary:
Note that Preview-6 is not available as an extension, so either use Preview-5 or deploy as self-contained.
Couldnt put a picture in the comment, so I thought i'd show it here. This is my current publish wizard.
Just did it with a brand new project via new project -> Asp.net core web application -> blazor (Asp.net core hosted) built and published fine to azure app service fine.
My answer is:
Configure the publish profile to "Self-contain" deployment mode.
Edit all .csproj files to change <TargetFramework>...</TargetFramework> node name to <TargetFrameworks>...</TargetFrameworks>. (see also: https://stackoverflow.com/a/42855070 )
Fix the web root folder path string at runtime in Startup class like below.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Serialization;
using System.IO;
using System.Linq;
namespace BlazorHostedOnAzure.Server
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson();
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseResponseCompression();
// ---- APPEND PART.1 BEGIN ----
var clientBlazorWebRootPath = default(string);
// ---- APPEND PART.1 END ----
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBlazorDebugging();
}
// ---- APPEND PART.2 BEGIN ----
else
{
if (env.WebRootPath != null)
{
var pathOfIndex = Path.Combine(env.WebRootPath, "index.html");
var pathOfContent = Path.Combine(env.WebRootPath, "_content");
if (!File.Exists(pathOfIndex) && Directory.Exists(pathOfContent))
{
clientBlazorWebRootPath = Directory.GetDirectories(pathOfContent).FirstOrDefault();
if (clientBlazorWebRootPath != null)
{
env.WebRootPath = clientBlazorWebRootPath;
}
}
}
}
// ---- APPEND PART.2 END ----
app.UseClientSideBlazorFiles<Client.Startup>();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
});
// ---- APPEND PART.3 BEGIN ----
if (clientBlazorWebRootPath != null)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(clientBlazorWebRootPath)
});
}
// ---- APPEND PART.3 BEGIN ----
}
}
}
I published my sample code and README on the GitHub my repository.
https://github.com/sample-by-jsakamoto/BlazorHostedV3Preview6OnAzureWebApp#how-to-configure-client-side-blazor-v300-preview-6-that-is-hosted-on-an-aspnet-core-server-to-deploy-it-to-azure-at-13-jul-2019

Xamarin.Forms PlatformParametwer does not contain a constructor that takes 2 arguments

I am doing a mobile app using ADAL for authentication. I am using VS 2017 Xamarmin.Forms and trageting .Net standard 2.0 for the project. But got the error for the following code. I did some research than found out that PlatformParameters constructor is not supported by .NetCore since .NetCore does not support UI yet. But .Net Standard should support. Is there any solution or workaround? Thank you in advance.
authResult = await authContext.AcquireTokenAsync(resource, clientID, new Uri(clientReturnUri), new PlatformParameters(PromptBehavior.Auto, this));

Resources