如何告诉我的.NET应用程序在哪里查找所需的特定程序集(除了GAC或运行应用程序的文件夹)?例如,我想将一个程序集放在用户的Temp文件夹中,让我的应用程序知道引用的Assembly在temp文件夹中.
谢谢
我的应用程序包含对外部库(SQL Server管理对象)的引用.显然,如果运行时系统中不存在该库,则只要没有调用使用此库中的类的方法,应用程序仍然可以工作.
问题1:这是指定行为还是CLR加载库的方式(幸运)副作用?
要检测引用是否可访问,我目前使用如下代码:
Function IsLibraryAvailable() As Boolean
Try
TestMethod()
Catch ex As FileNotFoundException
Return False
End Try
Return True
End Function
Sub TestMethod()
Dim srv As New Smo.Server() ' Try to create an object in the library
End Sub
Run Code Online (Sandbox Code Playgroud)
它有效,但似乎很难看.注意如果TestMethod的是一个单独的方法,它才能正常运行,否则异常将在抛出开头的IsLibraryAvailable(在try-catch之前,即使对象实例化try-catch块内occurrs).
问题2:有更好的选择吗?
特别是,我担心函数内联等优化可能会阻止我的代码工作.
如何将程序集保存到文件?即我的意思不是动态程序集,而是“正常”的内存程序集。
Assembly[] asslist = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly ass1 in asslist)
{
// How to save?
}
Run Code Online (Sandbox Code Playgroud)
当应用程序从资源加载某些引用的程序集时,可能会发生这种情况。我想将它们保存到磁盘。
不可能从资源中提取程序集,因为它们在那里加密。
我有两个单独的项目,例如project1和project2.那么我在project1中有一个window1,那么如何从project2中显示这个window1.
我使用visual studio 2010来设计网页,我使用了这个图层
编程,我使用gidview和objectdatasource,但我得到这个例外:
"The type 'WebApplication4.view1' is ambiguous: it could come from assembly
'C:\Users\EHSAN\AppData\Local\Temp\Temporary ASP.NET
Files\root\d04444bc\d654bde6\App_Code.i0fp6yrj.DLL' or from assembly
'C:\Users\EHSAN\Documents\Visual Studio
2010\Projects\WebApplication4\WebApplication4\bin\WebApplication4.DLL'. Please
specify the assembly explicitly in the type name."
Run Code Online (Sandbox Code Playgroud)
我把我的代码放在这里:
这是我的web.aspx:
<asp:ObjectDataSource ID="ObjectDataSource1" Runat="server" TypeName="WebApplication4.view1"
SelectMethod="Search" OldValuesParameterFormatString="original_{0}" >
</asp:ObjectDataSource>
Run Code Online (Sandbox Code Playgroud)
这是APP_Code中BAL文件夹中的search.cs文件:
namespace WebApplication4
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
public class view1 : System.Web.UI.Page
{
public view1()
{ }
public List<person> Search()
{
List<person> persons = new List<person>();
DataSet ds = PersonsDB.Search();
foreach …Run Code Online (Sandbox Code Playgroud) 我在 azure VM (WIN SERVER 2012) 的 iis 中开发了一个 SharePoint 提供程序托管 (MVC) 应用程序和托管 Web 应用程序。
当我们尝试使用应用程序使用应用程序时,它会引发以下错误。
“/”应用程序中的服务器错误。
无法加载文件或程序集“Microsoft.IdentityModel,版本=3.5.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。该系统找不到指定的文件。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.IdentityModel,Version=3.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。该系统找不到指定的文件。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。
程序集加载跟踪:以下信息有助于确定无法加载程序集“Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的原因。
警告:程序集绑定日志已关闭。要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 设置为 1。注意:有一些与程序集绑定失败日志记录相关的性能损失。要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
我已经在服务器中安装了 dotNet 3.5 和 4.5。仍然有同样的错误。谁能帮我?
我试图migrate.exe从EntityFramework特定的DLL上运行该应用程序.此DLL引用Microsoft.Azure.KeyVault.WebKeynuget包.
当我尝试运行命令时
./migrate MyProject.Data /startUpDirectory=C:\myDir /startUpConfigurationFile=C:\myDir\Redirect.config
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
错误:无法加载文件或程序集"Newtonsoft.Json,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6ae ed"或其中一个依赖项.定位的程序集的清单定义与程序集引用不匹配.(HRESULT除外:0x80131040)
通常我会说这是因为它正在寻找版本6 Newtonsoft.Json而无法找到它.但我有一个绑定重定向指向最新版本.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
所以,我不明白为什么这不会重定向到版本9.0.0.0,它只查找版本6.0.0.0.
我已经反编译了Microsoft.Azure.KeyVault.WebKey.dll,我可以看到它正在引用版本,6.0.0.0所以这是为什么它正在寻找那个版本,但我不明白为什么它不重定向.
我正在尝试下载 libcheck。但 Microsoft.com 上的链接已损坏,也无法在 Microsoft.com 上搜索
这个工具已经停产了吗?如果是的话,微软还有其他工具可以替代这个工具吗?
我有一个 .NET Standard 2.0 DLL 项目。
它没有其他参考,除了NETStandard.Library 2.0.1一切都很好。
它被 WPF 应用程序引用,一切似乎都正常。
将 nuget 包添加System.Collections.Immutable 1.5.0到 DLL 项目后,Dependencies解决方案资源管理器的根目录上会出现一个黄色感叹号。(嗯......我现在看到即使在我删除这个包后感叹号仍然存在,但我想这是一个 VS 错误,因为在添加这个库之前一切似乎都很好)
拥有这两个包,一切都很好,但是当我尝试使用 时ImmutableDictionary,我得到了这个:
System.IO.FileNotFoundException: '无法加载文件或程序集 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一。该系统找不到指定的文件。'
查看 nuget 包,我明白这两个应该一起工作,因为(根据我的理解)'System.Collections.Immutable` 库说它支持 .NET 标准 2.0。
我对 .NET Standard 世界很陌生。
查看System.Collections.Immutable.dll我的主应用程序bin文件夹中的公钥令牌,我发现它确实b03f5f7f11d50a3a如预期的那样。不过版本不一样。
通常,在旧的 .NET 中,我会尝试在应用程序的配置文件中添加程序集重定向。但在这里这样做似乎没有任何区别。将此添加到我引用 DLL 的 WPF 应用程序中:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
...将异常更改为:
System.IO.FileNotFoundException: '无法加载文件或程序集 …
.net c# .net-assembly assembly-binding-redirect .net-standard-2.0
问题:无法在 CSharpScript 中使用外部定义的类型,因为我猜由于某些程序集不匹配,它无法将对象类型从自身转换为自身。
我有 2 个项目。
常见的
using System;
namespace Common
{
public class Arguments
{
public string Text;
}
public class Output
{
public bool Success;
}
}
Run Code Online (Sandbox Code Playgroud)
和
CSharp脚本实验
using System;
using System.Collections.Generic;
using Common;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
public class Parameters
{
public string text;
public Arguments arguments;
}
namespace CSharpScriptingExperiment
{
class Program
{
static void Main(string[] args)
{
ScriptOptions options = ScriptOptions.Default.WithImports(new List<string>() { "Common" });
options = options.AddReferences(typeof(Arguments).Assembly);
// Script will compare the …Run Code Online (Sandbox Code Playgroud) .net-assembly ×10
c# ×7
.net ×4
.net-core ×1
asp.net ×1
asp.net-mvc ×1
csharpscript ×1
disk ×1
reference ×1
reflection ×1
save ×1
wpf ×1