GVKun编程网logo

c# – 由Environment.FailFast崩溃的WPF(c#+wpf)

12

在本文中,我们将带你了解c#–由Environment.FailFast崩溃的WPF在这篇文章中,我们将为您详细介绍c#–由Environment.FailFast崩溃的WPF的方方面面,并解答c#+

在本文中,我们将带你了解c# – 由Environment.FailFast崩溃的WPF在这篇文章中,我们将为您详细介绍c# – 由Environment.FailFast崩溃的WPF的方方面面,并解答c#+wpf常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的@ ng-toolkit / serverless错误消息:文件(./src/environments/environment.prod.ts)不存在、Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?、Angular environment.ts问题JSON但是environment.prod.ts、ASP.NET Core-Environment、IHostingEnvironment、IApplicationLifetime

本文目录一览:

c# – 由Environment.FailFast崩溃的WPF(c#+wpf)

c# – 由Environment.FailFast崩溃的WPF(c#+wpf)

我正在研究为Kiosk(触摸屏)构建的 WPF应用程序.我们为自己构建虚拟键盘.

有一个屏幕我们使用带有TextBox的DataGrid控件列出一些项目(最多4个项目).虚拟键盘显示焦点(这就是它的构建方式).

当我们随机选择不同的项目时,应用程序崩溃而不会到达通用异常处理程序.此问题在触摸屏上可重复,但在常规屏幕中不可重复.事件日志显示如下,

Application: CashNGo.WPF.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string
message).
Message: Unrecoverable system error.
Stack:
   at System.Environment.FailFast(System.String)
   at MS.Internal.Invariant.FailFast(System.String,System.String)
   at MS.Internal.Invariant.Assert(Boolean,System.String)
   at System.Windows.Documents.TextStore.VerifyTextStoreConsistency()
   at System.Windows.Documents.TextStore.GrantLock()
   at System.Windows.Documents.TextStore.GrantLockWorker(LockFlags)
   at System.Windows.Documents.TextStore.RequestLock(LockFlags,Int32 ByRef)
   at MS.Win32.UnsafeNativeMethods+ITextStoreAcpsink.OnSelectionChange()
   at System.Windows.Documents.TextStore.OnSelectionChanged()
   at System.Windows.Documents.TextSelection.System.Windows.Documents.ITextRange.NotifyChanged(Boolean,Boolean)
   at System.Windows.Documents.TextRangeBase.EndChange(System.Windows.Documents.ITextRange,Boolean,Boolean)
   at System.Windows.Documents.TextSelection.System.Windows.Documents.ITextRange.Select(System.Windows.Documents.ITextPointer,System.Windows.Documents.ITextPointer)
   at System.Windows.Controls.TextBox.Select(Int32,Int32)
   at System.Windows.Controls.TextBox.set_CaretIndex(Int32)
   at Common.Controls.softKeyboard.<.cctor>b__1c(System.Windows.Controls.TextBox)
   at System.Windows.Input.DelegateCommand`1[[System.__Canon,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]].Execute(System.__Canon)
   at Common.Controls.softKeyboard+<>c__displayClass5.<SoftKeyboardFocus_Changed>b__0()
   at System.Windows.Threading.dispatcher.Invoke(System.Action,System.Windows.Threading.dispatcherPriority,System.Threading.CancellationToken,System.TimeSpan)
   at System.Windows.Threading.dispatcher.Invoke(System.Action,System.Windows.Threading.dispatcherPriority)
   at Common.Extensions+<>c__displayClass1.<DelayedInvoke>b__0(System.Object,System.EventArgs)
   at System.Windows.Threading.dispatcherTimer.FireTick(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,Int32,System.Delegate)
  at System.Windows.Threading.dispatcherOperation.InvokeImpl()
   at System.Windows.Threading.dispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Object)
   at System.Windows.Threading.dispatcherOperation.Invoke()
   at System.Windows.Threading.dispatcher.ProcessQueue()
   at System.Windows.Threading.dispatcher.WndProcHook(IntPtr,IntPtr,Boolean
ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr,Boolean ByRef)
   at MS.Win32.HwndSubclass.dispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Delegate)
   at System.Windows.Threading.dispatcher.LegacyInvokeImpl(System.Windows.Threading.dispatcherPriority,System.TimeSpan,Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,IntPtr)
   at MS.Win32.UnsafeNativeMethods.dispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.dispatcher.PushFrameImpl(System.Windows.Threading.dispatcherFrame)
   at System.Windows.Threading.dispatcher.PushFrame(System.Windows.Threading.dispatcherFrame)
   at System.Windows.Threading.dispatcher.Run()
   at System.Windows.Application.Rundispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
   at CashNGo.WPF.App.Main()

我做了一些搜索,找到了http://social.msdn.microsoft.com/Forums/vstudio/en-US/dfbd2526-8953-4ce8-97c2-43246fd251c0/wpf-framework-crashing-on-setting-foxus-in-textbox?forum=wpf,这是完全相同的例外.

任何建议都会有所帮助.

解决方法

关闭一个名为的Windows服务.
Tablet PC Input Service

@ ng-toolkit / serverless错误消息:文件(./src/environments/environment.prod.ts)不存在

@ ng-toolkit / serverless错误消息:文件(./src/environments/environment.prod.ts)不存在

如何解决@ ng-toolkit / serverless错误消息:文件(./src/environments/environment.prod.ts)不存在?

在有1个项目的有角工作区中安装ng-toolkit / serverless时,出现以下错误: 错误消息:文件(./src/environments/environment.prod.ts)不存在。

有人面对同样的事情吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?

Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?

如何解决Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)??

我一直在开发一款多语言 Angular 应用,并将其部署到 Firebase 托管。

https://myAppDomain.de/de 显示德文版。
https://myAppDomain.de/en 显示英文版。

这在大多数情况下都可以正常工作,除了我将一些特定于语言环境的变量放入 environment.ts 中:

numberFormatLocale: ''de'',dateFormatLocale: ''de-DE'',timePickerLocale: ''de-DE'',momentLocale: ''de'',...

我希望这些值根据应用程序的语言而改变。

因此,我创建了单独的 environment.ts 文件:

environment.ts 作为英文开发环境文件,
environment.prod.ts 作为英文 prod 环境文件,
environment.de.ts 作为德语开发环境文件,
environment.prod.de.ts 作为德国生产环境文件,

我试图在构建过程中替换它们,所以我这样配置 angular.json

   "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser","options": {
            "i18nMissingTranslation": "error","localize": true,"outputPath": "dist/myAppDomain","index": "src/index.html","main": "src/main.ts","polyfills": "src/polyfills.ts","tsConfig": "tsconfig.app.json","assets": [
              "src/favicon.ico","src/assets","src/manifest.webmanifest",{
                "glob": "**/*","input": "node_modules/ngx-auth-firebaseui/assets/","output": "./assets/"
              }
            ],...
          },"configurations": {
                "production": {
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts","with": "src/environments/environment.prod.ts"
                    },{
                      "replace": "src/environments/environment.de.ts","with": "src/environments/environment.prod.de.ts"
                    }
                  ],...
                },"de": {
                  "localize": [
                    "de"
                  ],"baseHref": "/de/","fileReplacements": [
                    {
                      "replace": "src/environments/environment.prod.ts","with": "src/environments/environment.prod.de.ts"
                    },{
                      "replace": "src/environments/environment.ts","with": "src/environments/environment.de.ts"
                    }
                  ]
                },"en": {
                  "localize": [
                    "en"
                  ],"baseHref": "/en/"
                }
              },},

但是,它不起作用。我总是得到英文环境.ts,不管我加载哪个语言版本。

我该如何正确配置?或者,有什么更好的方法可以实现相同的目标?

2021-07-31 更新: 这是我的package.json的摘录:

  "scripts": {
    "ng": "ng","start": "ng serve --configuration=en --port 4200 && ng serve --configuration=de --port 4201","start:en": "ng serve --configuration=en --port 4200","start:de": "ng serve --configuration=de --port 4201","build": "ng build","build:prod": "ng build --configuration=production","test": "ng test","lint": "ng lint","e2e": "ng e2e"
  },

我还从我的 angular.json 中添加了一些更多信息。

解决方法

我决定走另一条路。我没有使用大量单独的环境文件(添加的语言越多越乏味),而是回到只有两个环境文件:一个用于开发,一个用于生产。

我创建了一个 locale.ts 类,它包含一个用于每个变量的函数,我曾经在 environment.ts 中使用过,如下所示:

  private static numberFormatLocaleCache: string;

  /**
   * Number format locale
   */
  static numberFormatLocale(): string {
    if (!this.numberFormatLocaleCache) {
      const currentLang = Locale.getCurrentLang();
      switch (currentLang) {
        case ''de'':
          this.numberFormatLocaleCache = ''de'';
          break;
        default:
          this.numberFormatLocaleCache = ''en'';
      }
    }
    return this.numberFormatLocaleCache;
  }

函数 getCurrentLang() 从当前路径中提取当前语言。对于https://myAppDomain.de/de,它返回''de'';对于 https://myAppDomain.de/en,它返回 ''en''。这是它的实现:

  /**
   * Delivers the current lang.
   * @return language,e.g. ''en''
   */
  static getCurrentLang(): string | undefined {
    const path = window.location.pathname.replace(window.location.href,'''');
    const parts = path.split(''/'');
    if (parts.length < 2)
      // The path does not contain a language code
      return undefined;
    const currentLang = return parts[1];
    return currentLang;
  }

注意:我首先尝试使用 Angular 模块来确定当前路径,例如this.router.url 来自 import { Router } from ''@angular/router'';。 但是,如果调用组件不是当前的 <router-outlet>,则这些都不能正常工作。例如,如果 Locale 类不是搜索组件的一部分,我会得到 https://myAppDomain.de/de/search 而不是 https://myAppDomain.de/de。

Angular environment.ts问题JSON但是environment.prod.ts

Angular environment.ts问题JSON但是environment.prod.ts

在这里您可以看到错误。 现在,在控制台中将其标记,但不在文件中标记。

enter image description here

ASP.NET Core-Environment、IHostingEnvironment、IApplicationLifetime

ASP.NET Core-Environment、IHostingEnvironment、IApplicationLifetime

Environment:静态类

 

System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");//读取环境变量

 

 

IHostingEnvironment对象中是一些该应用程序的环境信息,包括程序名称信息,根目录,环境名称 等等基本信息

await context.Response.WriteAsync($"name=\"{env.ApplicationName}\"");
await context.Response.WriteAsync($"name=\"{env.ContentRootFileProvider}\"");
await context.Response.WriteAsync($"name=\"{env.ContentRootPath}\"");
await context.Response.WriteAsync($"name=\"{env.EnvironmentName}\"");
await context.Response.WriteAsync($"name=\"{env.WebRootFileProvider}\"");

 ASP.NET Core 在应用启动时读取环境变量 ASPNETCORE_ENVIRONMENT,ASPNETCORE_ENVIRONMENT 可设置为任意值,但框架仅支持三个值:Development(开发)、Staging(测试)、Production(生产)。 如果未设置 ASPNETCORE_ENVIRONMENT,则默认为 Production(即生产环境)

env.IsDevelopment();//是否开发环境
env.IsProduction();//是否生产环境
env.IsStaging();//是否测试环境
env.IsEnvironment("xxx");//是否自定义环境

设置环境变量的三种方法:

1、在CMD中设置(临时): set ASPNETCORE_ENVIRONMENT=Staging 

2、电脑环境变量全局设置:我的电脑属性→环境变量→ASPNETCORE_ENVIRONMENT :Development

3、代码层次launchSettings.json中配置,配置文件中有两个选项,一个是IIS Express,一个是项目名称,这两个对应上面VS工具栏不同的启动方式,省略的话默认为 Production环境。

注意:前两种方式只适用于通过命令启动的模式,如: dotnet ManyEnvironment.dll 

 

IApplicationLifetime对象是用来绑定应用程序的运行时事件的

applicationLifetime.ApplicationStarted.Register(() =>
            {
                Console.WriteLine("Strated");
            });
applicationLifetime.ApplicationStopping.Register(() =>
            {
                Console.WriteLine("Stoping");
            });
applicationLifetime.ApplicationStopped.Register(() =>
            {
                Console.WriteLine("Strated");
       }

 

 

 参考:https://www.cnblogs.com/yaopengfei/p/10904178.html

 

未完待续...

关于c# – 由Environment.FailFast崩溃的WPFc#+wpf的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于@ ng-toolkit / serverless错误消息:文件(./src/environments/environment.prod.ts)不存在、Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?、Angular environment.ts问题JSON但是environment.prod.ts、ASP.NET Core-Environment、IHostingEnvironment、IApplicationLifetime的相关知识,请在本站寻找。

本文标签: