gpt4 book ai didi

.net - 反射 GetExecutingAssembly 正在抛出 StackOverflow

转载 作者:行者123 更新时间:2023-12-03 18:27:44 28 4
gpt4 key购买 nike

我正在尝试使用反射获取当前正在执行的程序集的路径以用于注册某些类型。这是在静态/共享方法中调用的

Dim Path = System.Reflection.Assembly.GetExecutingAssembly.Location

此行引发 StackOverflow 异常,其中包含以下详细信息:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
System.StackOverflowException
Data: unable to evaluate expression.
HelpLink: unable to evaluate expression.
HResult: unable to evaluate expression.
InnerException: unable to evaluate expression.
Message: unable to evaluate expression.
Source: unable to evaluate expression.
StackTrace: unable to evaluate expression.
TargetSite: unable to evaluate expression.

调用是在主线程上进行的。我正在使用 .Net 4.5/VS11 Beta

备案, GetEntryAssembly , GetCallingAssembly ,等等......都做同样的事情。我以前从未见过(甚至读过)这种行为 - 有没有人有任何建议?

编辑:

操作系统:Win7 x64 Ultimate
这是一个 Winforms 应用程序

我有一个共享方法,它应该返回一个依赖解析器(包装在我自己的类中以对其进行抽象)。
Private Shared _Resolver As IDependencyResolver
Public Shared Function QuickResolver() As IDependencyResolver
If _Resolver Is Nothing Then
Dim Container = New WindsorContainer
''Line below was breaking so I exploded it into multiple lines as shown above
Dim CurrentPathFilter = New AssemblyFilter(IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location))

Container.Register(
Component.For(Of Interfaces.ISomeInterface)().
ImplementedBy(Of DAL.SomeType).LifestylePerThread)

''.... More registrations ....

Dim Resolver As New WindsorDependencyResolver(Container)
_Resolver = Resolver
End If
Return _Resolver
End Function

它是单例的(我知道初始化应该重构为不同的方法 - 它在我的列表中)

它从 Winforms UI 线程调用如下:
    Resolver = Common.DependencyResolverFactory.QuickResolver
ScanRepository = Resolver.Resolve(Of IRepository(Of Scan))()
GetExecutingAssembly 抛出异常行(这是异常中断的地方)我承认这是不寻常的,所以我假设这是我的代码使其接近 SO 并且 GetExecutingAssembly 方法嵌套得足够深以致溢出?

最佳答案

使用以下示例代码获取程序集目录。

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))

或者
Path.GetDirectoryName(typeof(Foo).Assembly.ManifestModule.FullyQualifiedName)

关于.net - 反射 GetExecutingAssembly 正在抛出 StackOverflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10531488/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com