问题
We are moving part of our server to .net 4.0. We already did the move to Vs2010 as a first step but did not change the target framework of any project.
As a second step I'm moving a specific part of our server to target 4.0 so we can use some of the new functionality.
I've run into a problem when calling TLBexp.exe on a Class library DLL that targets 4.0. This DLL also references a lot of DLLs that target 2.0.
I get the error: TlbExp : error TX0000: Could not load file or assembly 'file:Library.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
I am calling the TLBExp that comes with: Microsoft SDKs\Windows\v7.0A\bin\ In the command I call in the VS2010 command prompt I reference v4.0.30319 binaries (such as mscorlib.tlb)
Is running TLB on a 4.0 DLL that references 2.0 libraries allowed? If yes then any reason why I'm getting this error.
Here is the exact command call i use: "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\tlbexp.exe" /silent /win32 /tlbreference:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb" /tlbreference:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.tlb" /tlbreference:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.tlb" /tlbreference:"C:\Windows\system32\stdole2.tlb" C:\Dev\Library.dll
Thanks
回答1:
I had an assembly targeting 4.0, that referenced another assembly which had a target framework of 3.5.
As a result, I was getting the same error on a "post build" step. By trial and error, I discovered that the version of TLBExp found in this folder: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
could generate the TLB file successfully.
HTH!
回答2:
You can use the following path to TlbExp, which will be picked up automatically based on project framework version:
$(TargetFrameworkSDKToolsDirectory)\tlbexp.exe
来源:https://stackoverflow.com/questions/5669459/tlbexp-exe-errorthis-assembly-is-built-by-a-runtime-newer