相关疑难解决方法(0)

在c#中是否有类似于Application_Start的类库

当从另一个程序集实例化时,我想在类库中执行某些代码.是否有类库的入口点或引导程序?我认为一个静态方法Main可以做到这一点,但我错了.此应用程序可能是配置和实例化记录器单例,未处理的异常处理程序等.

.net c# class-library

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

AssemblyResolve没有为依赖项触发

我现在正在与AssenblyResolve活动挣扎一段时间.我搜索了stackoverflow并做了其他谷歌搜索,并尝试了所有我认为相关的.以下链接更接近我的问题(在我看来):

  1. 未调用AssemblyResolve,并且在序列化期间抛出FileNotFoundException

  2. 在类库中处理AssemblyResolve事件的位置?

我有一个带有静态方法的Bootstrapper类(我将删除我们拥有的线程安全代码,只是为了清楚起见:

public static void Initialize()
{
    AppDomain.CurrentDomain.AssemblyResolve += CustomResolve;
}

private static Assembly CustomResolve(object sender, ResolveEventArgs args)
{
    // There is a lot code here but basicall what it does.
    // Is determining which architecture the computer is running on and
    // extract the correct embedded dll (x86 or x64). The code was based
    // on milang on GitHub (https://github.com/milang/P4.net). And it's the same
    // purpose we want to be able to load the x86 or x64 …
Run Code Online (Sandbox Code Playgroud)

c# assemblyresolve

16
推荐指数
2
解决办法
7162
查看次数

PowerShell 二进制模块程序集依赖错误

我正在开发PowerShell 二进制模块。它使用Json.NET和其他库。

我收到此异常“无法加载文件或程序集 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一。系统找不到指定的文件。”

在硬盘上,我有一个更新版本(版本 7.0.2)

像这样的问题在控制台、网络或桌面应用程序中很容易解决,通过这样的行使用app.config或“web.config”

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

如何为 PowerShell 二进制模块做类似的事情?

c# powershell json .net-assembly

5
推荐指数
2
解决办法
1801
查看次数