如何修复ilmerged DLL(在nuget包中)和Consuming Application之间的类型不匹配。无法通过参数 [英] How to fix Type Mismatch between ilmerged DLL (in a nuget package) and Consuming Application. Unable to pass paramter

查看:74
本文介绍了如何修复ilmerged DLL(在nuget包中)和Consuming Application之间的类型不匹配。无法通过参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个服务dll,它引用了System.Web.OData(来自Microsoft.AspNet.OData.5.9.0)

I have a service dll, which has a reference to System.Web.OData (from Microsoft.AspNet.OData.5.9.0)

服务dll有一个公开的方法,它接收OData.Delta<>

这个服务dll在编译时是ilmerged,所以它有这个"版本"。嵌入数据。

The service dll has an exposed method which takes in an OData.Delta<>
This service dll when compiled is ilmerged, so it has this "version" of Data embedded.

现在消费应用程序也引用了相同的OData,但它来自corext,全球化缓存。

Now the consuming application, also has a reference to the same OData, however, it comes from a corext, globalized cache.

然而,当消费应用程序尝试调用具有OData.Delta<>的方法时参数,它抱怨它无法从ConsumingApp.OData.Delta转换为ServiceDll.OData.Delta。

However, when the consuming application, attempts to call the method that has an OData.Delta<> parameter, it complains that it cannot convert from ConsumingApp.OData.Delta to ServiceDll.OData.Delta.

我如何确保参数使用实际正确的"版本"? OData.Delta让它们不冲突?

How would I go about making sure that the parameter uses the actual proper "version" of OData.Delta so that they do not conflict?

我似乎找不到像...一个NameSpace.For.ServiceDll,它可以让我专门针对OData.Delta那个嵌入在ilmerge中

I can't seem to find like.. a NameSpace.For.ServiceDll that would enable me to specifically target the OData.Delta that is embedded in the ilmerge

推荐答案

此问题没有通用解决方案。类型和命名空间名称不唯一标识类型,包括程序集。因此,如果在2个不同的程序集中具有相同的类型/命名空间,那么它与CLR有2个不同的类型。你可以
不再转换一个到你可以将A类转换为B类,C#没有实现结构等价的概念。

There is no general purpose solution to this issue. Type and namespace names don't uniquely identify a type, the assembly is included. Therefore if you have the same type/namespace in 2 different assemblies then it is 2 separate types to the CLR. You can no more convert one to the other than you could convert class A to class B, C# doesn't implement the concept of structural equivalence.

如果这真的是一个service(我假设是web或WCF)然后实际的类型名称不相关,因为它无论如何都会被序列化。但是,如果您正在使用服务引用,那么您将与服务引用生成的代码紧密相关。

If this is really a service (I assume web or WCF) then the actual type name isn't relevant as it'll get serialized anyway. However if you're using a service reference then you are being strongly tied to the service reference generated code.

在某些情况下,您可以编写一个包装器,将一个转换为另一个但运行编译期间的问题,因为来自2个不同程序集的同一名称空间中的相同类型将无法编译。 C#不允许在程序集级别使用别名。所以
你最终不得不使用反射来动态加载至少一个程序集,然后将数据转换为你想要使用的类型。

In some cases you can write a wrapper that converts one to the other but you run into issues during compilation since the same type in the same namespace coming from 2 different assemblies won't compile. C# doesn't allow aliasing at the assembly level. So you end up having to use reflection to dynamically load at least one of the assemblies and then convert the data to the type you want to use.

可能还有其他方法我没有考虑过,但上面是我过去如何解决这个问题。

There may be other approaches that I haven't considered but the above is how I've worked around the issue in the past.

我个人建议您完全删除ILmerge并简单地依赖于共享数据。这允许服务和客户自己引入引用并完全解决问题。

Personally I would recommend that you remove the ILmerge altogether and simply take a dependency on the shared data. This allows the service and clients to pull in the references themselves and resolves the issue completely.

Michael Taylor

http://www.michaeltaylorp3.net

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于如何修复ilmerged DLL(在nuget包中)和Consuming Application之间的类型不匹配。无法通过参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆