问题描述
完整的错误消息:Could not load file or assembly 'LimitlessSoft.Buffer,Version=4.0.0.0,Culture=neutral,PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
首先,我查看了这些问题及其所有答案:
- Could not load file or assembly or one of its dependencies
- Could not load file or assembly (custom dll) - works for console but fails for web project (ASP.NET MVC 5) [duplicate]
- Could not load file or assembly '***.dll' or one of its dependencies
我还没有找到任何适合我的解决方案。
这是我的情况。
我有 winform .NET Framework 4.0
项目(不,我无法更新到更高版本)。我有一些代码,我想在 dll
中分开,这样我就可以在其他项目中使用它。我创建了一个只有一个类的新 .NET Framework 4.0 Class Library
项目,它看起来像这样:
using System;
namespace LimitlessSoft.Buffer
{
/// <summary>
/// Used to buffer data
/// </summary>
/// <typeparam name="T"></typeparam>
public class Buffer<T>
{
/// <summary>
/// Delegate that returns object that is buffered
/// </summary>
/// <returns></returns>
public delegate T SetBuffer();
/// <summary>
/// SetBuffer that returns object that is buffered
/// </summary>
private SetBuffer UpdateBuffer;
/// <summary>
/// Indicates when has buffer been updated last time
/// </summary>
public DateTime LastUpdate { get; set; }
private T Value { get; set; }
/// <summary>
/// Initializes new buffer
/// </summary>
/// <param name="updateBuffer">Delegate that returns object being buffered</param>
public Buffer(SetBuffer updateBuffer)
{
UpdateBuffer = updateBuffer;
}
/// <summary>
/// Gets item from buffer that has been last time updated not greater than maximumObselence.
/// If it cannot be found,he will do as updateIfNotFound says.
/// If it cannot be foudn after updateIfNotFound,you will get default(T)
/// </summary>
/// <param name="maximumObselence">Maximum obselence for buffered item</param>
/// <param name="updateIfNotFound">Indicates if buffer need to be updated if it has not been found at given period</param>
/// <returns></returns>
public T Get(TimeSpan maximumObselence,bool updateIfNotFound = true)
{
if (Value != null)
if ((LastUpdate - DateTime.Now).TotalMilliseconds < maximumObselence.TotalMilliseconds)
return Value;
if (updateIfNotFound)
{
Value = UpdateBuffer();
LastUpdate = DateTime.Now;
return Value;
}
return default(T);
}
/// <summary>
/// Sets item into buffer
/// </summary>
/// <param name="item"></param>
public void Set(T item)
{
Value = item;
LastUpdate = DateTime.Now;
}
/// <summary>
/// Updates data in buffer
/// </summary>
public void Update()
{
Value = UpdateBuffer();
LastUpdate = DateTime.Now;
}
}
}
当我在我的项目中导入这个类库时,它会抛出错误。
然后我创建了新的空 .NET Framework 4.0 winform application
,导入了这个 dll
,初始化了类,从中调用了函数,然后它就可以工作了。
为什么相同的 dll 可以在新的空项目中运行,但在其他项目中会出错?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)