开发者

Dispose() causes dreaded Visual Studio "Unable to copy file from obj to bin' error?

After searching many solutions I just found out that the overridden Dispose method of a Control causes the dreaded VS bug "Cannot copy file from obj/ to bin/ ..." (in my case)

If this Dispose method is included, VS will throw the error each time you make code changes and try to rebuild. If the overridden dispose method is commented out, problems disappear ...

What is going on here? Am I doing something wrong, or is this a Visual Studio feature?

public class StyledLabel : Control
{
    private ImageList imageList;

    public ImageList ImageList
    {
        get { return imageList; }
        set { imageList = value; }
    }

    public StyledLabel()
    {
        SetStyle(ControlStyles.ResizeRedraw, true);
        SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        SetStyle(ControlStyles.UserPaint, true);
    }        

    // This method causes dreaded VS Error ??
    prote开发者_如何转开发cted override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (imageList != null)
            {
                imageList.Dispose();
            }
        }
        base.Dispose(disposing);
    }
}

Edit: unfortunately I cannot reproduce the error anymore, so I'm even more lost now ... The vs error message went away though...


Try clearing the ImageList before disposing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜