.tlh generated on two machines is different

I have a .NET dll that has some interfaces \ classes that are affected by com. during the build procedure a .tlb file is created, and some C ++ code refers to this tlb. As a result, the compiler creates a .tlh file for tlb.

When I run the assembly locally, one of the properties in one of the interfaces ends with the corresponding method in tlh, which does not have the same name. The property in the .net code is called PropertyA end, which is called get_propertyA, and PropertyB ends with the name get_PropertyB. I didn’t beat for a century when this happened, I just used the method defined in tlh and assumed that everything was hunky dory, however, when I introduced these changes, the assembly did not work for anyone else, because the compilers generated properties called get_PropertyA and get_PropertyB (random case mismatch in propertyA).

The tlb files generated on both machines are identical (according to hexadecimal matching), and the tlh files are generated by the same version of the compiler.

The build procedure creates tlb by executing: path regasm \ to \ dll \ Mydll.dll -tlb: path \ to \ output \ mydll.tlb

Any ideas why my local version ends with a property with the wrong name? Or what can I do to fix this?

UPDATE: I read that tlbexp will use the first version of the string found and which can be changed by recompiling. Although I do not use tlbexp, I wondered if this was a problem. I found parameters with the same name as my method (in other ways), but with a lowercase letter at the beginning. So I replaced all of these. Rebuilt, unchanged. Then I renamed my COM method. Built and received the expected missing method errors. Renamed the method back to its original name, and it looks like it has been fixed. Since it works now, and I cannot make it crash again, I cannot try the suggested solutions, but I like the idea of ​​renaming in case this happens in the future.

+6
compiler-construction interop com
source share
3 answers

You can use the rename attribute for import to explicitly rename properties. Say you have propA , which sometimes becomes propA and propB , which sometimes becomes propB . To always use propA and propB , use renaming as follows:

 #import <library> rename( "propA", "PropA" ) rename( "propB", "PropB" ) 

Use this with caution - this results in a simple text replacement that works for any identifiers found in the type library. In some cases, this can lead to debugging of unwanted side effects.

+4
source share

I have the same problem.

Through another SO question ( https://stackoverflow.com/questions/708721/compare-type-libraries-generated-by-tlbexp ) I found this community content:

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/5003c486-ed3f-4ec8-8398-a1251b0f9e74

Quote from this content:

The tlbexp documentation has one useful community content:

http://msdn2.microsoft.com/en-gb/library/hfzzah2c(VS.80).aspx

Quote:

"The reason for the / names parameter is that type libraries store each identifier in a case-insensitive table. The first case we encounter wins. Thus, a class called Monitor can be set as a" monitor "if there is a parameter with such a name occurs first. (And the order in which identifiers occur can be changed simply by recompiling your assembly!) / names can guarantee a stable shell. "

The main reason seems to be a midl error, described here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;220137

Quote:

"When there are two identifiers that differ only in the case, the case of the second identifier is changed to reflect the case of the first."

So, as a solution, I disabled the "register for COM interop" option in the project settings and added steps after the build

"$ (DevEnvDir) .... \ SDK \ v2.0 \ Bin \ tlbexp" $ (TargetFileName) / names: "$ (ProjectDir) Names.txt"% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ regasm $ (TargetFileName)

The name file contains a query that determines how to perform capillation. In my case, it contains only one line:

ID

Best wishes

Bernd ritter

Using / names solved this problem for me.

+4
source share

Conformity check: are you absolutely sure that the same #import directive is used on both machines? that is, exactly the same source files compiled?

Try to create a network resource from the directory containing the project, and open it on another computer to be sure at 1000%, these are the same source files that are compiled.

Sorry, I have no more specific suggestions.

0
source share

All Articles