【发布时间】:2012-02-27 07:28:06
【问题描述】:
我在 VB.NET 模块中创建了几个扩展方法。我将它们放在一个类中,构建它并获得 DLL。
我从另一个程序中引用了该 DLL 并使用 Imports 导入它。
扩展方法出现在 IntelliSense 中并且可以正常工作,但错误控制台中出现警告,提示:
无法解析此引用。找不到程序集“nK0deExtendedMethods”。检查以确保该程序集存在于磁盘上。
有谁知道为什么会出现这个错误,即使我已经引用了 DLL?
这是我使用扩展方法放置模块的类。
Imports System.Runtime.CompilerServices
Imports System.Drawing
Namespace nK0deExtendedMethods
Public Module ExtMethods
<Extension()>
Public Function Merge(ByVal img1 As Image, ByVal img2 As Image) As Image
Dim bmp As New Bitmap(Math.Max(img1.Width, img2.Width), img1.Height + img2.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(img1, 0, 0, img1.Width, img1.Height)
g.DrawImage(img2, 0, img1.Height, img2.Width, img2.Width)
g.Dispose()
Return bmp
End Function
'Public Class NewImageMethods
'End Class
End Namespace
我还有一个疑问。在Imports 语句中,我必须提到DLL 的名称以及Namespace 名称。像这样,
Imports ExtendedMethods.nK0deExtendedMethods
通常您只需要导入命名空间的名称,对吗?为什么会这样?
非常感谢大家。
【问题讨论】:
-
您是否尝试过清理和重建您的解决方案?
-
@AmenAyach 是的,但没有任何改变。
-
在那些糟糕的情况下,我使用进程监视器 (technet.microsoft.com/fr-fr/sysinternals/hh205949) 来检查 dll 加载失败的位置。祝你好运。
-
我整理出来了,伙计们。我创建了一个新类,删除了类名和
Namespace,插入了模块并再次构建它。解决了这两个问题。感谢您的回复。欣赏它:)
标签: vb.net visual-studio-2010 .net-4.0 vb.net-2010