我有一个解决方案,简而言之,它包含一个 Windows 窗体应用程序项目和一个类库,两者都使用 C#。我的图书馆项目被命名为OldName. 因此命名空间也是OldName,生成的文件是OldName.dll.
我想改名字,让我走进属性,更改从大会名称OldName来NewName。
建筑现在生成一个NewName.dll. 但是,当我的应用程序尝试访问这个 dll 时,我得到一个System.Runtime.Serialization.SerializationException(该 dll 包含我用于二进制序列化某些东西的方法):它声称Unable to find assembly 'OldName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.Procmon.exe 确认它正在寻找旧的 dll ( NAME NOT FOUND)。
现在奇怪的是,如果我复制 并将其NewName.dll重命名为OldName.dll,这样我就有OldName.dll和NewName.dll,问题仍然存在。如果我删除NewName.dll并只离开OldName.dll,程序在启动时崩溃:System.IO.FileNotFoundException: Could not load file or assembly 'NewName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.这一次,Procmon.exe …
c# clr filenotfoundexception visual-studio-2010 .net-assembly
对于解决方案中的几乎所有项目,我都会收到以下警告:
Contract reference assembly for project 'X.X.X' not found. Select 'Build' or 'DoNotBuild' for Contract Reference in project settings.
Run Code Online (Sandbox Code Playgroud)
但是我无法找到任何可以在visual studio中设置此选项的提示.
任何帮助都非常感谢.
感谢致敬
我有一个非常简单的 ASP.NET 项目,当我从 Visual Studio 运行它时工作得很好,但是在我发布到 Azure Web App 后我收到了这个错误
无法加载文件或程序集“Microsoft.Owin.Security,Version=2.0.1.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)
我四处看了看,我没有使用——至少不是故意的——这个程序集,如果我在解决方案中进行搜索,它没有列在 Web.config 或 Package.config 或任何地方。
我真的不知道我在这里错过了什么。也许是 Azure 方面的配置。
这是堆栈跟踪
[FileLoadException: Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] SampleWebApp.Startup.ConfigureAuth(IAppBuilder app) +0 SampleWebApp.Startup.Configuration(IAppBuilder app) +5
[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object …
每当我完成任务时,它总是让我感到困惑Path-Resolution.我有关于报告问题的以下信息:
ASP.NET MVC-5 Applicationfont fileieMyriadPro-SemiBold.ttf//a value receives a path + name of the file in variable i.e. name
string name = "myApplicationName.fonts.MyriadPro-Semibold.ttf";
//object (named as assembly) of class System.Reflection.Assembly.
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(name))
// stream always gets null value (don't know why!)
{
if(stream != null)
{
//myCode waiting for above stream not to be null :-(
}
else
{
throw new ArgumentException("No resource with name " …Run Code Online (Sandbox Code Playgroud) 这一个错误让我疯了.
我在我的一个名为BaseServices的类库中安装了SendGrid NuGet包,它依赖于Newtonsoft.Json v7.0.1,所以它将它安装在我的packages文件夹中并引用它.
在类库中,我有这个绑定重定向:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
在ASP.NET MVC应用程序的web.config中,即使用我的类库的客户端应用程序,我有一个小于v6版本的程序集绑定重定向指向Newtonsoft.Json库的v6,如下所示:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral"
publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
当我运行我的电子邮件发送BaseServices库中的代码时,我收到此错误:
线程0x1a4c已退出,代码为0(0x0).System.IO.FileLoadException:无法加载文件或程序集Newtonsoft.Json,版本= 7.0.0.0,文化=中性公钥= 30ad4fe6b2a6aeed'或它的一个依赖.定位的程序集的清单定义与程序集引用不匹配.(从HRESULT异常:0x80131040)文件名: 'Newtonsoft.Json,版本= 7.0.0.0,文化=中性公钥= 30ad4fe6b2a6aeed' 在SendGrid.Helpers.Mail.Mail.Get()在BaseServices.EmailService.SendAsync(EmailMessage消息)在MyFolder\BaseServices\EmailService.cs中:第39行
===预绑定状态信息===日志:DisplayName的= Newtonsoft.Json,版本= 7.0.0.0,文化=中性公钥= 30ad4fe6b2a6aeed(完全指定的)LOG:应用平台=文件:/// MyFolder文件/网络/日志:初始PrivatePath = MyFolder\Web\bin调用程序集:SendGrid,Version = 7.0.3.0,Culture = neutral,PublicKeyToken = 4f047e93159395ca.===日志:此绑定在默认加载上下文中启动.日志:使用应用程序配置文件:MyFolder\Web\web.config日志:使用主机配置文件:C:\ Users\computer\Documents\IISExpress\config\aspnet.config日志:使用C:\ Windows\Microsoft中的计算机配置文件.NET \框架\ v4.0.30319\CONFIG\machine.config中.日志:后政策参考:Newtonsoft.Json,版本= 7.0.0.0,文化=中性公钥= 30ad4fe6b2a6aeed LOG:尝试新的URL文件下载:/// C:/用户/计算机/应用程序数据/本地/温度/临时ASP.NET Files/root/ef9cacdf/e639667a/Newtonsoft.Json.DLL.日志:新的URL文件的尝试下载:/// C:/用户/计算机/应用程序数据/本地/温度/ ASP.NET临时文件/根/ ef9cacdf/e639667a/Newtonsoft.Json/Newtonsoft.Json.DLL.日志:尝试下载新的URL文件:///MyFolder/Web/bin/Newtonsoft.Json.DLL.警告:比较程序集名称导致不匹配:主要版本错误:无法完成程序集的设置(hr = 0x80131040).探测终止.
IsAssembly, IsPublic, IsFamily, IsFamilyOrAssembly, IsFamilyAndAssembly我已经阅读过相关内容,但我无法理解每个人的作用。这里奇怪的是IsFamily,在代码中返回并IsAssembly返回False,但IsFamilyOrAssembly返回True.
有人可以解释每个属性,因为我发现从文档中很难理解。当我开始阅读 c# 中的反射时,我遇到了所有这些。
public class Example
{
public void m_public() {}
internal void m_internal() {}
protected void m_protected() {}
protected internal void m_protected_public() {}
public static void Main()
{
Console.WriteLine("\n{0,-30}{1,-18}{2}", "", "IsAssembly", "IsFamilyOrAssembly");
Console.WriteLine("{0,-21}{1,-18}{2,-18}{3}\n",
"", "IsPublic", "IsFamily", "IsFamilyAndAssembly");
foreach (MethodBase m in typeof(Example).GetMethods(
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
if (m.Name.Substring(0, 1) == "m")
{
Console.WriteLine("{0,-21}{1,-9}{2,-9}{3,-9}{4,-9}{5,-9}",
m.Name,
m.IsPublic,
m.IsAssembly,
m.IsFamily,
m.IsFamilyOrAssembly,
m.IsFamilyAndAssembly
);
} …Run Code Online (Sandbox Code Playgroud) 出于某种原因,当我尝试加载一些程序集并对其进行分析时,出现错误 Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly...
我真的不在乎为什么会抛出这个异常,我知道缺少的程序集在哪里。
除了AppDomain.CurrentDomain.AssemblyResolveMono.Cecil 之外,还有一种方法可以处理诸如事件之类的事情吗?我可以手动加载丢失的程序集,但我不知道如何加载。
那么,如何为 Mono.Cecil 加载程序集?
我使用 Visual Studio 2017 创建了我的 Azure Function v2。
我创建了一个新的队列触发器函数。
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace Functions
{
public static class queue
{
[FunctionName("queue")]
public static void Run([QueueTrigger("myqueue-items", Connection = "test")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是找不到QueueTrigger的程序集
Error CS0246 The type or namespace name 'QueueTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'QueueTrigger' could not be …Run Code Online (Sandbox Code Playgroud) 公告告诉我们:
程序集卸载能力是 AssemblyLoadContext 的一项新功能。从 API 的角度来看,这项新功能在很大程度上是透明的,仅通过几个新 API 公开。它允许卸载加载器上下文,释放实例化类型、静态字段和程序集本身的所有内存。应用程序应该能够通过这种机制永远加载和卸载程序集而不会出现内存泄漏。
此外,这个设计说明提到了“静态”。
我试过这个简单的测试:
static void Main()
{
Proxy.X = 15;
var alc = new AssemblyLoadContext("MyTest", true);
var asm = alc.LoadFromAssemblyName(typeof(Program).Assembly.GetName());
var proxy = (Proxy)asm.CreateInstance(typeof(Proxy).FullName);
Console.WriteLine(proxy.Increment());
}
class Proxy
{
public static int X;
public int Increment() => ++X;
}
Run Code Online (Sandbox Code Playgroud)
它输出“16”,这意味着隔离不起作用。
我的目标是对可以抛出异常的类静态成员进行单元测试。通常的测试可以通过触发类型初始值设定项来影响彼此的行为,因此我需要以尽可能便宜的方式隔离它们。测试应在 .NET Core 3.0 上运行。
这样做是否正确,并且可以提供AssemblyLoadContext帮助?
.NET 中程序集的标记类型是什么?
我正在通过教程学习 AutoMapper,我marker types for assemblies在这里遇到了over的概念:
// Or marker types for assemblies:
var configuration = new MapperConfiguration(cfg =>
cfg.AddMaps(new [] {
typeof(HomeController),
typeof(Entity)
});
);
Run Code Online (Sandbox Code Playgroud)
在寻找我的问题的答案时,我遇到了这个问题。但我无法在那里找到答案。
.net-assembly ×10
c# ×7
.net ×5
asp.net ×1
assemblies ×1
automapper ×1
azure ×1
build ×1
clr ×1
json.net ×1
mono.cecil ×1
resources ×1
static ×1
types ×1