Closed yeganehaym closed 1 year ago
Hey @yeganehaym, thanks for reaching out. Just to clarify, are you using a Blazor Server app, within a WinForms app, through a WebView? If so, the recommended approach for this is to leverage Blazor Hybrid, which supports WinForms directly, without involving Blazor Server.
If you are in fact running the Blazor Server app within a webview in WinForms, you may be running into permissions issues. Note this is not a supported configuration.
Hi @yeganehaym. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
i dont know but its working on some systems. on a system : first time couldn't open dialog but the next release could but not working now. looklike every time is different we run app as admin what permission i need to provide?
i dont know but its working on some systems.
Without more information on your environment and app configuration, there isn't much help we can provide here.
Just to clarify, are you using a Blazor Server app, within a WinForms app, through a WebView?
Hi @yeganehaym. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
i dont know but its working on some systems.
Without more information on your environment and app configuration, there isn't much help we can provide here.
Just to clarify, are you using a Blazor Server app, within a WinForms app, through a WebView?
yes we made a blazor server app and making win app with windows form with .net core my ide is rider
we use webview2 runtime to show desktop window
Are you able to provide a minimal, public, github repository which reproduces this issue?
By:
we use webview2 runtime to show desktop window
Are you suggesting you're navigating to the Blazor Server app in the WebView2 control within the WinForms app? Or are you running a native Blazor Hybrid app using WinForms? You can learn more about Blazor Hybrid here.
Hi @yeganehaym. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Blazor Server app in the WebView2 control within the WinForms app.
github repo is private but i put form1 code here
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Principal;
using MediatR;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using RollCall.Blazor.Shared;
using RollCall.Blazor.Shared.Helper;
using RollCall.Common.StartupMethods;
using RollCall.Data.SqlServer;
using RollCall.Blazor.Shared.Component.Toast;
using RollCall.Common.MediateR.Behaviors;
using RollCall.Common.MediateR.Commands.Devices;
using MatBlazor;
using RollCall.AppLib.Communication.Mail;
using SubPrject.Core.ApplicationServices;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.Internal;
using Newtonsoft.Json;
using RollCall.Dto.Auth;
namespace RollCall.Winform;
public partial class Form1 : Form
{
public Form1()
{
try
{
InitializeComponent();
this.MinimumSize = new Size(800, 600);
this.WindowState = FormWindowState.Maximized;
this.ShowIcon = true;
ExternalAuthStateProvider.RootPath = System.IO.Directory.GetCurrentDirectory();
var path = GetPath();
#if !DEBUG
this.Icon = new Icon(Path.Combine(path, "logo.ico"));
#endif
var serviceCollection = new ServiceCollection();
serviceCollection.AddBlazorWebView();
serviceCollection.AddAuthorizationCore();
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
serviceCollection.AddSingleton<ExternalAuthStateProvider>();
serviceCollection.AddSingleton<ExternalAuthService>();
serviceCollection.AddTransient<IConfiguration>(sp =>
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("appsettings.json");
return configurationBuilder.Build();
});
#if DEBUG
serviceCollection.AddBlazorWebViewDeveloperTools();
#endif
//================= Configs ====================================
serviceCollection.AddMediatR(typeof(CreateOrUpdateDeviceCommandHandler));
serviceCollection.AddMatBlazor();
//=========== Data Services =====================================
serviceCollection.AddAppServices();
serviceCollection.AddScoped(typeof(IPipelineBehavior<,>), typeof(DataLoggingBehavior<,>));
//serviceCollection.AddElmahLogger(builder.Configuration);
serviceCollection.AddMailServer();
serviceCollection.AddTypeConfigs();
serviceCollection.AddAppToastService();
serviceCollection.AddScoped<IAppToast, MatBlazorToast>();
//serviceCollection.AddHangfireService(builder.Configuration);
serviceCollection.AddBlazorContextMenu();
serviceCollection.AddBlazorDownloadFile();
serviceCollection.AddHttpContextAccessor();
serviceCollection.AddEntityFrameworkSqlServer();
serviceCollection.AddScoped<IUnitOfWork>(serviceProvider =>
serviceProvider.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContext());
var filePath = Path.Combine(path, "db.config");
string constr=String.Empty;
if (File.Exists(filePath))
{
var json = File.ReadAllText(filePath);
var connectionModel = JsonConvert.DeserializeObject<DbConnectionModel>(json);
constr =
$"Server={connectionModel.Server};Database={connectionModel.DatabaseName};{(!connectionModel.UserAuth?"Trusted_Connection=True;":"User Id=zpuser;Password=Z@manP@rdaz;")}TrustServerCertificate=true;MultipleActiveResultSets=true";
}
else
{
constr =
"Server=zamanpardaz;Database=zamanpardaz;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=true";
}
serviceCollection.AddDbContextFactory<ApplicationDbContext>((serviceProvider, c) => c.UseSqlServer(constr
,
options =>
{
var minutes = (int)TimeSpan.FromMinutes(3).TotalSeconds;
options.CommandTimeout(minutes);
c.UseInternalServiceProvider(serviceProvider);
}));
serviceCollection.AddScoped<IDbInitializerService, DbInitializerService>();
serviceCollection.AddSingleton<IWebHostEnvironment>(new WebHostEnvironment()
{
ContentRootPath = path,
WebRootPath = Path.Combine(path, "wwwroot")
});
serviceCollection.AddSingleton<IHostEnvironment>(new HostingEnvironment()
{
ContentRootPath = path
});
serviceCollection.AddWindowsFormsBlazorWebView();
var services = serviceCollection.BuildServiceProvider();
var scopeFactory = services.GetRequiredService<IServiceScopeFactory>();
using (var scope = scopeFactory.CreateScope())
{
var applicationDbContext = scope.ServiceProvider.GetService<ApplicationDbContext>();
try
{
var dbInitializer = scope.ServiceProvider.GetService<IDbInitializerService>();
dbInitializer.Initialize();
dbInitializer.SeedData();
GlobalApp.CanConnect = true;
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("خطا در اتصال به دیتابیس"+ Environment.NewLine + e.Message, "Sql Error");
}
if (GlobalApp.CanConnect)
{
GlobalApp.DeviceStatusModes = applicationDbContext.DeviceStatusModes.ToList();
}
}
blazorWebView1.HostPage = @"wwwroot\index.html";
blazorWebView1.Services = services;
blazorWebView1.RootComponents.Add<App>("#app");
blazorWebView1.Dock = DockStyle.Fill;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private string GetPath()
{
var path = Environment.ProcessPath;
var fileExt = Path.GetFileName(path);
path = path.Replace(fileExt, "");
return path;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
something i found out when i run app as admin it happens and dialog doesn't open but when i just dbl click on the exe, open dialog is ok
Ah got it, from the looks of it, you're running a Blazor Hybrid application, and not a Blazor server application within a WinForms webview.
Just tried reproducing your issue in Debug & Release configurations, as well as in a published app. I'm not seeing any issues with opening the input file dialogue.
If you still believe this is a framework issue, we'll need a minimal, public, GitHub repository which reproduces this issue.
Hi @yeganehaym. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
this is the structure of my project i got a shared project of blazor server and this shared between winforms and blazor
also you need to run "WinForm App" as admin to see input file not working
i got a shared project of blazor server and this shared between winforms and blazor
So is the *Blazor.Shared
project a Blazor Server project, or a Razor Class Library (RCL)?
Hi @yeganehaym. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
*.shared project is a class library that is set by
<PropertyGroup>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
and *.blazorServer project and winform proj is referenced to share proj and for windows i use this package
PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="6.0.101-preview.11.2349" />
Ah I see, thanks for the details. 6.0.101-preview.11.2349
is from 12/13/2021
. Can you please try the latest .NET 7 build or 6.0.547 and confirm if you're still having the issue? If so, we'll need a minimal, public, GitHub repository which reproduces the issue to investigate further.
Hi @yeganehaym. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Is there an existing issue for this?
Describe the bug
i have made an app with blazor server and launch dektop version with winform but when i make release version of desktop application. input file doesn't react to click of user and i cant pickup any file but on some systems opens but it looklike code doesn't continue but it's ok on blazor server project and windows form when i run app in rider
Expected Behavior
i can pick up file in file browser when i click on inputfile
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6
Anything else?
No response