我正在尝试使用反射来获取当前正在执行的程序集的路径,以用于注册某些类型。这是在静态/共享方法中调用的
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 方法嵌套得足够深以至于溢出?