Preserving compatibility with an Interop dll

I asked this question a couple of weeks ago and thought I had solved it, but I was wrong.

When creating an interop dll in C#, any time I alter the code and re-compile, I lose the reference to it from any applications that reference it (like VB etc).

This is a sample application. I thought I was doing everything write by specifying the GUID etc but nope. Any ideas

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.IO;

using System.Net;

using System.Collections.Specialized;

using System.Text;

using System.Runtime.InteropServices;

namespace myNameSpace

{

[GuidAttribute("3097DFF8-0FA1-4356-A9DF-DAFB1C177BE5")]

[ClassInterface(ClassInterfaceType.AutoDual)]

public class MyClass

{

public MyClass(){}

public string testMethod() {

return "OK";

{

}

}



Answer this question

Preserving compatibility with an Interop dll

  • Piquet

    Thank you for the reply, however, I am not using a .Net language to reference this dll. I wish I had that option because if I did, I wouldn't have to bother with all of this Interop madness. I am actually referencing it from VB6. Every time I re-compile the C# dll, when I go into references in my VB6 apps, the reference shows up as missing. I have to remove it, and then re-add it, then re-compile every VB6 program that has a reference to the dll. I have quite a few so this is driving me insane.

    When you create a dll in VB6, it is automatically COM compatible, and you can also set the version compatibility to "binary" which means the compatibility will never be broken when you re-compile... I shouldn't say never, because if you add classes and what-not, you have to break it, but just changing the code inside of existing functions will not break it. If VB6 can do this, C# HAS TO!!!!!

    I am just having a hard time believing no one else has found a way around this. I've searched the web quite a bit to no avail. I did find one site that explains adding GuidAttribute will ensure binary compatibility but it isn't working for me.


  • bhowden

    hi

    i noticed that 2.. i think thats because the version of the dll counts and every time you recomplie and you overwrite the last one the version of the dll is diffrent from the one you refenrceed

    .. i think the Specific Version is the problem .. when you reference it you should set the Specific Version to false..

    You should give it a try .. go at References section right click on your dll and click propreties .. and you should see the Specific Version proprety


    Hope This Helps if not come back.. and .. will make it out


  • LEBRUN Thomas

    Add the GUID to Your assemblyinfo like this ....

    using System.Runtime.InteropServices;

    [assembly: Guid("23E5AAA6-7FC6-48e4-98A8-1D4E7610D3E8")]

    this should fix your problem ....


  • mikelostcause

    I suspect you have an attribute [AssemblyVersion("1.0.*")] in your AssemblyInfo.cs file. This creates a new version each time you build, which will break compatibility.

    Try using an explicit version like [AssemblyVersion("1.0.0.0")] . Also take a look at ComCompatibleVersionAttribute in MSDN for the day you need to increment AssemblyVersion but still want to preserve CLSIDs that are backwards compatibility with earlier versions.


  • guzzy

    Joe, thank you thank you thank you! That did it. I have spent hours on this. Love that it's hidden in some stinking text file >:( Throws me back to the days of configuring Apache via text configuration files. Oh well... part of the learning curve I guess. Thank you again. This is absolutely what I needed. I have some posts on other boards so I will upate them with this info in case it can help anyone else in the future.

    And to the person who replied after Joe, thank you for the reply, but I did have the Guidattribute statement and that alone didn't solve the issue. I had to have that AND edit the AssemblyInfo.cs file.

    Jeff


  • Preserving compatibility with an Interop dll