【发布时间】:2012-03-16 22:29:22
【问题描述】:
我有以下代码:
namespace ConectorV2
{
[assembly:InternalsVisibleTo("Pruebas")]
internal static class Utilidades
{
internal static string extraerCadenaDeConexion()
{
return extraerCadenaDeConexion(new XElement());
}
internal static string extraerCadenaDeConexion(XElement documento)
{
throw new NotImplementedException();
}
}
}
然后在 Pruebas 项目中:
namespace Pruebas.ConectorV2.Cliente
{
[TestFixture]
class ModuloExtraerCadenaDeConexion
{
[Test]
public void devuelveCadenaSolicitada()
{
var mock = new MockRepository();
var appSettings =
XElement.Parse(
@"<appSettings>
<setting key='dbtype' value='SQLSERVER' />
<setting key='SQLSERVER' value='prueba' />
</appSettings>");
Assert.That(ConectorV2.Utilidades.extraerCadenaDeConexion(appSettings), Is.EqualTo("prueba"));
}
}
}
编译时出现以下错误:
命名空间 Pruebas.ConectorV2 中不存在类型或命名空间名称“Utilidades”(您是否缺少程序集引用?)
我的 pruebas 项目中正确引用了该程序集,我在 msdn 上读到项目的默认程序集名称是项目名称......我错过了什么?
【问题讨论】:
-
您是否对其中一个或两个程序集应用了强名称签名?
-
不,虽然我觉得我不需要
-
好的,所以我签署了两个程序集,现在它说“Conector.Utilidades”由于其保护级别而无法访问
-
您不需要签名。但是,如果这样做,则需要在 InternalsVisibleTo 属性中使用强名称。