小编San*_*zen的帖子

引用两个相等的程序集,只有公钥不同

我的Visual Studio 2008项目引用了两个(外部)程序集(A + B),这两个程序集恰好引用了相同的第三个程序集(C).但是,程序集A期望程序集C具有一个公钥,该公钥与程序集B期望的公钥不同.

这是一个明显例外的例子:

无法加载文件或程序集'Newtonsoft.Json,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = 9ad232b50c3e6444'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)

当然,我不能在同一目录中放置两个版本的C(只有公钥不同),因为它们的文件名是相同的.其次,我发现使用配置文件中的程序集绑定只允许版本映射,而不是公钥映射.

我还尝试将其中一个程序集C放在一个单独的目录中,并将CLR配置为在加载程序集时在该目录中进行搜索.不幸的是,我无法让它工作.

我知道重新编译其中一个外部库(其中一个恰好是开源的)可以解决这个问题,但如果不是绝对必要,我不想将这个负担添加到我的维护计划中.

所以我的问题是:如何引用程序集C的两个"版本",它们只有公钥不同?

UPDATE

我偶然发现了一个相关问题的答案,使用ilmerge提供了一个有趣的解决方案.我还没有检查过它,但对于遇到这个问题的人来说这可能是有用的.

.net assemblies reference visual-studio

7
推荐指数
2
解决办法
9182
查看次数

如何将属性值转换合并到NHibernate QueryOver .SelectList?

我希望将属性值转换合并到我的QueryOver查询中.

我喜欢在查询对象模式之后编写查询,直接生成MVC视图模型.在我的视图模型中,我尝试使用尽可能简单的属性类型,将转换复杂性保留在视图和控制器之外.这意味着有时候,我需要将一种类型转换为另一种类型,例如将日期转换为字符串.

有人可能会争辩说,这种转换应该在视图中执行,但由于我的大多数视图模型都直接转换为JSON对象,这会导致转换变得更加麻烦.在JavaScript中执行日期到字符串转换充其量是有问题的,我的JSON转换器不够灵活.

这是我正在做的一个例子:

// Entity.
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTimeOffset DateCreated { get; set; }
}

// View model.
public class CustomerViewModel
{
    public string Name { get; set; }
    public string DateCreated { get; set; } // Note the string type here.
}

// Query.
CustomerViewModel model = null;

List<CustomerViewModel> result = Session.QueryOver<Customer>()
    .SelectList(list => list
        .Select(n => n.Name).WithAlias(() => model.Name)
        .Select(n => …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate asp.net-mvc queryover

7
推荐指数
1
解决办法
6421
查看次数

根据验证程序,远程证书无效

我读了这篇博文. http://blogs.msdn.com/microsoftbob/archive/2009/08/20/a-wrapper-for-running-sql-server-2008-reporting-services-reports-anonymously.aspx 我们有一个类似的解决方案,我们已经使用了一年了.我们使用IReportServerConnection2接口实现直接向报表服务器提供凭据.自上个月以来,我们随机得到此错误.

底层连接已关闭.无法为SSL/TSL通道建立信任关系.内部异常:根据验证过程,远程证书无效.

我们一直使用SSL,它确实在一天中的大部分时间都有效.有趣的是,当我们收到此错误时,我们只需转到ASP.NET应用程序的web.config并更改文件的时间戳 - reportviewer再次开始工作.

SSL证书有效,大多数时间都会显示报告.但是一旦我们收到此错误,我们必须更改web.config以使其再次运行.

有任何想法吗.我感谢您的帮助.

certificate reporting-services

6
推荐指数
0
解决办法
2423
查看次数

没有错误时,CSharpCodeProvider不会返回编译器警告

我正在使用CSharpCodeProvider该类编译一个C#脚本,我在我的应用程序中用作DSL.如果有警告但没有错误,Errors则生成的CompilerResults实例的属性不包含任何项目.但是当我引入错误时,警告Errors也会突然出现在房产中.

string script = @"
    using System;
    using System; // generate a warning
    namespace MyNamespace
    {
        public class MyClass
        {
            public void MyMethod()
            {
                // uncomment the next statement to generate an error
                //intx = 0;
            }
        }
    }
";

CSharpCodeProvider provider = new CSharpCodeProvider(
    new Dictionary<string, string>()
    {
        { "CompilerVersion", "v4.0" }
    });

CompilerParameters compilerParameters = new CompilerParameters();
compilerParameters.GenerateExecutable = false;
compilerParameters.GenerateInMemory = true;

CompilerResults results = provider.CompileAssemblyFromSource(
    compilerParameters,
    script);

foreach …
Run Code Online (Sandbox Code Playgroud)

.net c# compiler-construction compilation .net-4.0

6
推荐指数
1
解决办法
996
查看次数

如何在保留其程序集元数据的同时强烈签署外部DLL?

我在项目中使用了一些未签名的库.因为我的应用程序是强签名的,所以库也必须如此.

我用以下方式签署这些库:

"%PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin\ildasm.exe" /nobar /all /out=library.il library.dll
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\ilasm.exe" /dll /key=MyKey.snk library.il
Run Code Online (Sandbox Code Playgroud)

问题是任何元数据(例如版本号)都会在现在签名的DLL中丢失.这是一个问题,因为现在库之间的某些依赖关系被破坏了.如何保留版本号而不需要实际编译这些库的源代码?

UPDATE

它实际上是一个显示此问题的特定DLL,我发现它是使用ILMerge构建的.也许这就是问题所在.需要明确的是:ILMerge生成的DLL确实具有正确的元数据,只有在反汇编和重组后,元数据才会消失.

更新2

我在Reflector中打开了DLL,看起来至少版本号仍在那里.我一直在使用Windows资源管理器中的文件属性对话框/详细信息选项卡进行检查.所以我认为这是缺少的清单.

.net assembly-signing ilasm

6
推荐指数
1
解决办法
1805
查看次数

如何控制MembershipProvider实例创建/生命周期?

我在Web.Config文件中注册了一个自定义MembershipProvider类.我正在使用Castle Windsor进行Inversion Of Control,我将自定义MembershipProvider类注册为瞬态(因为它使用的是瞬态服务).

这意味着我希望在每个Web请求上重新创建成员资格提供程序实例.目前,每个应用程序域只创建一次,因此当它尝试访问它所依赖的服务时,该服务实例在不应该被重用时被重用.

现在我需要找到一种方法让Windsor控制我的自定义MembershipProvider的生命周期,但我不知道如何.我期待一个工厂坐在.NET Framework的某个地方,允许我覆盖实例创建并将其重新路由到Windsor,但我找不到任何相似的东西.

顺便说一句,我使用的是.NET 4.0.

更新:这是我的一些代码,所以你可以看到我正在做的事情:

Web.Config中:

<membership defaultProvider="MyMembershipProvider" >
  <providers>
    <clear/>
    <add name="ApplicationMembershipProvider"
         type="MyNamespace.MyMembershipProvider, MyAssembly"/>
  </providers>
</membership>
Run Code Online (Sandbox Code Playgroud)

会员提供者

public class MyMembershipProvider : MembershipProvider
{
    private IMyService myService;

    public MyMembershipProvider() : base()
    {
        // We should use constructor injection here but since we cannot control
        // the construction of this class, we're forced to create the dependency
        // ourselves.
    }

    public override bool ValidateUser(string username, string password)
    {
        if (myService == null)
        {
            // This …
Run Code Online (Sandbox Code Playgroud)

.net asp.net castle-windsor asp.net-membership inversion-of-control

6
推荐指数
1
解决办法
2038
查看次数

如何使用FluentNHibernate映射具有复杂键类型(CultureInfo)的字典

我有字典,我正在使用Fluent NHibernate进行映射.字典具有复杂的密钥类型CultureInfo.我的数据库无法存储该类型,因此我想使用它的字符串表示形式.

在字典映射以外的映射中,我可以CultureInfo使用用户类型约定成功映射-properties.现在我想知道如何为dicationary映射做这件事.

这是包含字典的实体:

public class MultilingualPhrase : Entity
{
    private IDictionary<CultureInfo, string> languageValues;

    public virtual IDictionary<CultureInfo, string> LanguageValues
    {
        get
        {
            return languageValues;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是实体的自动映射覆盖:

public void Override(AutoMapping<MultilingualPhrase> mapping)
{
    mapping
        .HasMany(n => n.LanguageValues)
        .Access.ReadOnlyPropertyThroughCamelCaseField()
        .AsMap<string>("CultureName")
        .Element("Phrase")
        .Table("MultilingualPhraseValues");
}
Run Code Online (Sandbox Code Playgroud)

此映射(显然)会导致以下错误:

无法将CultureInfo中的参数值转换为String.

我知道NHibernate有一个类型自定义类型实现CultureInfo(我用它来映射属性)但是如何在我的映射覆盖中指定它?

.net c# nhibernate fluent-nhibernate

6
推荐指数
1
解决办法
1176
查看次数

如何为单个方案配置多个WCF绑定配置

我有一组IIS7托管的net.tcp WCF服务,它们为我的ASP.NET MVC Web应用程序提供服务.Web应用程序可通过Internet访问.

WCF Services (IIS7) <--> ASP.NET MVC Application <--> Client Browser

这些服务是用户名验证的,客户端(我的Web应用程序)用于登录的帐户最终作为主机上的当前主体.

我希望其中一个服务的身份验证方式不同,因为它为我的登录视图提供了视图模型.当它被调用时,客户端显然还没有登录.我认为,如果服务托管在与Web应用程序不在同一域中的计算机上,则Windows身份验证可以提供最佳或可能只是基于证书的安全性(实际上我也应该用于经过身份验证的服务).

但这不是重点.使用多个TCP绑定是给我带来麻烦的.我在我的客户端配置中尝试将其设置为:

<bindings>
  <netTcpBinding>
    <binding>
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
    <binding name="public">
      <security mode="Transport">
        <message clientCredentialType="Windows"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>

<client>
  <endpoint contract="Server.IService1" binding="netTcpBinding" address="net.tcp://localhost:8081/Service1.svc"/>
  <endpoint contract="Server.IService2" binding="netTcpBinding" bindingConfiguration="public" address="net.tcp://localhost:8081/Service2.svc"/>
</client>
Run Code Online (Sandbox Code Playgroud)

服务器配置如下:

<bindings>
  <netTcpBinding>
    <binding portSharingEnabled="true">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
    <binding name="public">
      <security mode="Transport">
        <message clientCredentialType="Windows"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>

<services>
  <service name="Service1">
    <endpoint contract="Server.IService1, Library" binding="netTcpBinding" address=""/>
  </service>
  <service name="Service2">
    <endpoint …
Run Code Online (Sandbox Code Playgroud)

wcf .net-4.0 wcf-binding wcf-security

5
推荐指数
1
解决办法
5809
查看次数

在IIS 7.5上运行时,如何调试使用PreApplicationStartMethodAttribute程序集属性设置的方法?

PreApplicationStartMethodAttribute在汇编级别上这样声明了:

[assembly: PreApplicationStartMethod(typeof(MyApp.Global), "InitializeApplication")]
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参见此说明

这是的声明InitializeApplication

public class Global : HttpApplication
{
    public static void InitializeApplication()
    {
        // Initialization code goes here...
    }
}
Run Code Online (Sandbox Code Playgroud)

我在本地IIS 7.5实例上运行应用程序,并且想调试InitializeApplication方法。我在上面设置了一个断点,但是没有被击中。

我认为代码是在应用程序池启动时执行的,据我所知,这是在Visual Studio中按F5之前的代码。

我试图将调试器附加到我能找到但无济于事的任何与IIS相关的过程。

我也意识到我可以使用Cassini进行调试,但是我需要在此修复与IIS相关的问题。

因此,问题是:如何调试PreApplicationStartMethodAttribute指定的方法?

debugging iis-7 visual-studio-2010

5
推荐指数
1
解决办法
572
查看次数

如何在NHibernate QueryOver查询中选择和使用值对象的集合

我有一个简单的模型,由一个使用引用对象引用一篇或多篇文章的文档组成(这是因为在域中,我们没有文章所以我们只能引用它们).

我正在尝试编写一个列出文档的查询,打印ID以及一个由逗号分隔的文章编号列表组成的字符串.例如:

ID ARTICLES
------------------
1  ACC, PE2,
2  ER0, AQ3, FEE
3  PE2
Run Code Online (Sandbox Code Playgroud)

我的问题是选择逗号分隔列表.

以下是域类:

// The Entity class has an Id property.
public class Document : Entity
{
    public virtual IEnumerable<ArticleReference> ArticleReferences { get; set; }
    public virtual DateTime ReceiveDate { get; set; }
}

// The ValueObject does not have an Id property ofcourse.
public class ArticleReference : ValueObject
{
    public virtual string ArticleNumber { get; set; }
    public virtual string ArticleName { get; set; }
} …
Run Code Online (Sandbox Code Playgroud)

.net c# nhibernate queryover

5
推荐指数
1
解决办法
1275
查看次数