小编Lee*_*Lee的帖子

用于编译的.NET绑定重定向

当我尝试编译一个使用已部署到我们客户端的文件的实用程序时,我收到以下错误.

程序集'*A*版本2.0.1.2'使用'*B*版本1.1.39.0',其版本高于引用程序集'*B*版本1.1.32.0'.

我们的客户端可以使用这些DLL没问题,因为我们有一个绑定重定向配置文件,它在运行时生效:

<dependentAssembly>
  <assemblyIdentity name="*B*" publicKeyToken="..." culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.1.32.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

为了给出一些背景知识,DLL存在于单独的解决方案中,因此一些引用是文件引用而不是项目引用,这只是我必须要忍受的东西!

是否有任何等效的绑定重定向适用于编译时?

我已经尝试使用调试DLL(版本1.0.0.0)进行编译,源代码回滚到上面的相关版本,但是我在运行时遇到以下错误:

定位的程序集的清单定义与程序集引用不匹配

也许构建服务器的配置与我的机器不同,但无论如何这似乎都不起作用......

.net c#

11
推荐指数
2
解决办法
3158
查看次数

找出合并基础会是什么

你怎么知道两个变更集之间的基础(三向合并)是什么?我试图解决为什么过去的合并没有像我预期的那样自动解决.

我想我正在寻找一种方法来找出与git merge-base命令相同的信息.如果没有命令/方式来做到这一点,我很高兴了解"基础选择"如何工作并手动完成.

merge tfs

9
推荐指数
1
解决办法
86
查看次数

使用类层次结构重载 - 大多数派生不使用

问题

我试图避免代码如下所示:

If(object Is Man)
  Return Image("Man")
ElseIf(object Is Woman)
  Return Image("Woman")
Else
  Return Image("Unknown Object")
Run Code Online (Sandbox Code Playgroud)

我认为我可以通过方法重载来实现这一点,但它总是选择最少的派生类型,我认为这是因为重载是在编译时确定的(与重写不同),因此只能在以下代码中假设基类:

代码结构:

NS:Real
   RealWorld (Contains a collection of all the RealObjects)
   RealObject
     Person
       Man
       Woman
NS:Virtual
   VirtualWorld (Holds a reference to the RealWorld, and is responsible for rendering)
   Image (The actual representation of the RealWorldObject, could also be a mesh..)
   ArtManager (Decides how an object is to be represented)
Run Code Online (Sandbox Code Playgroud)

代码实现(关键类):

class VirtualWorld
{
    private RealWorld _world;

    public VirtualWorld(RealWorld world)
    {
        _world = world;
    } …
Run Code Online (Sandbox Code Playgroud)

c# overloading class-hierarchy

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

使用ref表示参数将被修改

我理解 ref 意味着当方法返回时提交的引用可能指向一个完全不同的对象。

然而,我喜欢 ref 修饰符的一点是,开发人员立即知道在方法返回时他输入的内容可能会有所不同,因为调用方也需要 ref 修饰符。

从假设的 ORM 中采用一种简单的方法:

public Boolean AddItem(Entity someEntity)
{
  try
  {
    // Add item to database
    // Get Id of entity back from database
    someEntity.Id = *returnedId*;
    return true;
  }
  catch (DBException ex)
  {
    return false;
  }
}
Run Code Online (Sandbox Code Playgroud)

该方法的任何调用者可能不知道他们的实体已通过调用该方法进行更新。然而,将 someEntity 设为 ref 参数,它向开发人员表明他们提交的参数将有所不同,然后他们知道深入研究文档/代码以找出它是如何更改的,如果没有修饰符,他们可能从未想过这样做。

我知道这稍微滥用了 ref 修饰符,因为上面的示例中实际上并不需要它,但是以这种方式使用它实际上会给我带来任何问题吗?

c# theory language-design

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

为什么我的堆栈跟踪缺少步骤?

我记录的堆栈跟踪似乎缺少一步.

private void StartLoadingResources(DataService separateDataService)
{
    ...
    batchResource.Resources.Add(key, new List<string>());
    // batchResource.Resources is the Dictionary object involved
    ...
}
Run Code Online (Sandbox Code Playgroud)

为什么堆栈跟踪直接从去StartLoadingResourcesInsert(缺少的Add步骤)?

System.AggregateException: One or more errors occurred. ---> System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at MyApp.Importer.StartLoadingResources(DataService separateDataService) in ****\MyApp\MyApp\Importer.cs:line 313
   at MyApp.Importer.<Execute>b__5() in ****\MyApp\MyApp\Importer.cs:line 142
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at …
Run Code Online (Sandbox Code Playgroud)

.net c# stack-trace

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