小编MrV*_*ype的帖子

未处理的承诺拒绝:错误:注射器已被销毁

在最近关闭的这个问题中:https://github.com/angular/angular/issues/44186

贡献者(@jessicajaniuk)

我们相信这个问题可以通过 destroyAfterEach: true 解决。如果您发现需要 destroyAfterEach: false 的失败,则测试中可能存在范围泄漏。如果您仍然看到原始问题,请为其打开一个新问题。

我想知道是否有人可以详细说明或建议如何识别“范围蔓延”的策略

升级到 Angular 13 后我也遇到了这个问题destroyAfterEach: true

unit-testing jasmine angular

17
推荐指数
3
解决办法
2万
查看次数

如何跨多台计算机同步本地托管的Greasemonkey脚本?

我希望能够在我使用的所有机器上访问我的Greasemonkey脚本.我已经在Greasemonkey的设置对话框中启用了" 为用户脚本启用Firefox同步 "设置,但之后我读到它只同步外部托管的脚本.

然后我尝试使用以下方法设置同步:

  1. 我将Greasemonkey的' gm_scripts '文件夹(位于%appdata%\Mozilla\Firefox\Profiles\<profile name>)移动到OneDrive文件夹.
  2. 我在原始位置创建了一个指向上面提到的OneDrive文件夹的符号链接: mklink /D gm_scripts "%userprofile%\SkyDrive\App Profile Synching\GreaseMonkey\gm_scripts"
  3. 我在另一台机器上设置了相同的符号链接,并检查了符号链接的工作原理.

结果,我的脚本继续在原始机器中显示正常.但它们在第二台机器上根本没有显示出来.这似乎表明Greasemonkey在另一个位置有一些脚本列表.

如何解决此问题,或者有哪些其他方法可用于在多台计算机上同步我自己的Greasemonkey脚本?

firefox greasemonkey sync

12
推荐指数
1
解决办法
2341
查看次数

当类型为 C# 9 记录时,FluentAssertions Should().BeEquivalentTo() 在简单情况下会失败,看似将对象视为字符串

我最近开始使用 FluentAssertions,它应该具有强大的对象图比较功能。

我正在尝试做最简单的事情:将Address对象的属性与对象的属性进行比较AddressDto。它们都包含 4 个简单的字符串属性:国家/地区、城市、街道和邮政编码(它不是生产系统)。

有人可以向我解释一下,就像我两岁一样,出了什么问题吗?

partnerDto.Address.Should().BeEquivalentTo(partner.Address)
Run Code Online (Sandbox Code Playgroud)

它失败并显示以下消息:

信息:

预期结果。地址为 4 Some street, 12345 Toronto, Canada,但找到了 AddressDto { Country = Canada, ZipCode = 12345, City = Toronto, Street = 4 Some street }。

有配置:

  • 使用声明的类型和成员
  • 按值比较枚举
  • 按名称匹配成员(或抛出)
  • 没有自动转换。
  • 严格遵守字节数组中项目的顺序

它似乎试图将Address对象视为字符串(因为它覆盖了ToString()?)。我尝试使用该options.ComparingByMembers<AddressDto>()选项,但似乎没有什么区别。

AddressDto是一个record顺便说一句,不是一个class,因为我正在这个项目中测试新的.Net 5功能;但这可能没有什么区别。)


故事的道德启示:

使用FluentAssertionsrecord代替Trips,因为记录会在后台class自动覆盖,并且 FluentAssertions 假设它应该使用而不是属性比较,因为覆盖可能是为了提供所需的比较。Equals()Equals()Equals()

Equals()但是,在这种情况下, in a 的默认重写实现record实际上仅在两种类型相同时才有效,因此它会失败,因此 FluentAssertions 报告 上的失败BeEquivalentTo() …

c# fluent-assertions .net-5

11
推荐指数
2
解决办法
9605
查看次数

如何禁用整个 Blazor EditForm 以及所有字段?

我习惯了form.disable()Angular 反应式表单中的便捷方法,它禁用给定表单组(可以是整个表单)中的所有绑定字段。显然,以类似的方式启用它们也是可能的。

EditForm.NET5 Blazor中是否隐藏了类似的方法?

我还没有找到类似的东西。事实上,我什至还没有找到一种方法来迭代绑定到模型的所有字段。

.net-core blazor .net-5

9
推荐指数
1
解决办法
2316
查看次数

C# 9“init”属性可安全用于配置绑定(IOptions)吗?

我注意到新的initC# 版本 9 中的新属性在强类型选项类(选项模式)中使用时似乎是绑定的。

换句话说,这有效:

    class SomeSettings
    {
        public string FirstSetting { get; init; }
        public bool SecondSetting { get; init; }
    }

    ...

    configuration.GetSection(nameof(SomeSettings)).Get<SomeSettings>();
Run Code Online (Sandbox Code Playgroud)

但我们是否应该注意任何潜在的“陷阱”或限制?(当与直接绑定一起使用时,或IOptions<>Configure()注入时。)

诚然,我的动机是我正在考虑在配置时直接将这些实例绑定和注册为单例,而不需要讨厌的IOptions<>包装器。到目前为止我还没有这样做的唯一原因是属性的可变性,但init似乎解决了这个问题。

c# .net-core asp.net-core c#-9.0

5
推荐指数
1
解决办法
846
查看次数

尝试使用EventAggregator时Caliburn.Micro的DisplayRootViewFor方法中的NullReferenceException

我试图EventAggregator在我的WPF项目中使用Caliburn Micro内置的,基于这个文档.但是文档(我几乎总是在Caliburn Micro中找到它)似乎不完整,即示例代码不包含所有实现要求.

特别是,我没有在我的项目中使用IoC容器,我确信我丢失或滥用其配置的某些部分,这导致了问题.

问题:

  • 我在启动时进入NullReferenceExceptionDisplayRootViewFor方法.
  • 我显然知道NullReferenceException一般是什么,但我想知道如何解决这个问题,特别是与Caliburn Micro的app bootstrapper配置相关联(以及帮助其他用户在尝试做同样的事情时可能遇到同样的问题).

笔记:

  • 不可否认,我不清楚应用程序引导程序是如何工作的,因为我总是发现Caliburn Micro的文档非常难以理解(与MSDN相比),之前我没有使用过IoC容器.
  • NullReferenceException连接到GetInstance覆盖方法,因为如果我注释掉,我得到了"此对象定义无参数的构造函数"的异常.
  • 我已经在这个问题上尝试了解决方案,但它似乎没有任何区别.

有人可以向我解释为什么Caliburn.Micro抛出这个异常,以及我应该如何将其注入EventAggregator到我的主视图模型中?(因为尝试将其作为参数传递DisplayRootViewFor似乎不起作用.)


我的app bootstrapper如下所示 - 基于Event AggregatorSimple IoC Container文档页面的组合:

public class AppBootstrapper : BootstrapperBase
{
    private readonly SimpleContainer _container =
        new SimpleContainer();

    public AppBootstrapper()
    {
        Initialize();
    }

    protected override void Configure()
    {
        _container.Singleton<IEventAggregator, EventAggregator>();
    }

    protected override object GetInstance(Type serviceType, …
Run Code Online (Sandbox Code Playgroud)

c# wpf ioc-container caliburn.micro

3
推荐指数
1
解决办法
772
查看次数

Blazor WASM 异常导致数百个额外的套接字和连接异常

我刚刚开始学习 Blazor WASM(通常我是后端开发人员),我对经常发生的事情感到困惑。

这可能是一个非常菜鸟的问题,但请耐心等待。

为什么 Blazor 经常不断地抛出异常?

它从像这样的具体异常开始,我仍然理解这一点(显然作为一个完全的 Blazor 菜鸟,我不知道我在做什么;但唯一相关的部分是抛出异常):

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Microsoft.AspNetCore.Components.Forms.InputNumber`1[System.Int32] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputNumber`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] inside an EditForm.
System.InvalidOperationException: Microsoft.AspNetCore.Components.Forms.InputNumber`1[System.Int32] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputNumber`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] inside an EditForm.
   at Microsoft.AspNetCore.Components.Forms.InputBase`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at …
Run Code Online (Sandbox Code Playgroud)

c# .net-core blazor blazor-webassembly

3
推荐指数
1
解决办法
2434
查看次数

XAML:如何使用在“资源”节点中声明的&lt;Image&gt;类型资源?

这是我第一次必须在XAML中将图像用作资源。我已经通过以下方式在节点Image内声明了一种资源类型Window.Resources

<Window.Resources>
    <Image x:Key="MyIcon" Source="pack://application:,,,/Resources/Images/myicon.png"/>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

如何在XAML代码的其他部分中使用此资源?

必须是琐碎的,但是我没有找到有关如何使用Image类型资源的任何信息。

显然,将资源用作控件的Source属性Image不起作用:

        <WrapPanel Background="Transparent" Height="50">
            <Image Source="{StaticResource MyIcon}"/>
        </WrapPanel>
Run Code Online (Sandbox Code Playgroud)

上面的代码在设置Source属性时会引发异常,具体如下InnerException

{"'System.Windows.Controls.Image' is not a valid value for property 'Source'."}
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

1
推荐指数
1
解决办法
807
查看次数