Skip to content

Commit 57996ce

Browse files
committed
refactor: 增加异常保护
1 parent f0fcb7f commit 57996ce

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/extensions/BootstrapBlazor.Socket/Extensions/ActivatorExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5+
using BootstrapBlazor.Socket.Logging;
56
using System.Reflection;
67

78
namespace System;
@@ -20,7 +21,17 @@ public static class ActivatorExtensions
2021
public static object? CreateInstance(this Type type, object?[]? args = null)
2122
{
2223
var bindings = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
23-
return Activator.CreateInstance(type, bindings, null, args, null);
24+
25+
object? instance = null;
26+
try
27+
{
28+
instance = Activator.CreateInstance(type, bindings, null, args, null);
29+
}
30+
catch (Exception ex)
31+
{
32+
SocketLogging.LogError(ex, $"Create Instance {type.FullName} failed");
33+
}
34+
return instance;
2435
}
2536

2637
/// <summary>

0 commit comments

Comments
 (0)