简体   繁体   中英

Upgrading .NET from 3.5 to 4.5 breaks dependencies

An existing application targeting .NET 3.5 framework project uses a 3rd Party DLL. I decided retargeting to 4.5 to make use of default CultureInfo setting.

After retargeting, code calling the third party dll does not compile anymore.

It is a multi-language app (Engish / French) and I feel that this may be something to do with it as the error list from the build is now coming up in French. In 3.5 error list is in English.

My interpretation of the error message is:

"Impossible to incorporate the type interop 'Envox.ADXVoice.ADXVoiceClass.' Utilise the interface appropriate to the place." 

The app has various threads that conditionally invoke French culture and it would have been nice to move the test down into a base class and set the applications Default Culture.

Anybody struck a similar problem?

The verbatim error is:

Error   7   Impossible d'incorporer le type interop 'Envox.ADXVoice.ADXVoiceClass'. Utilisez l'interface applicable à la place. 

The English error message is:

error CS1752: Interop type 'Envox.ADXVoice.ADXVoiceClass' cannot be embedded. Use the applicable interface instead.

It is generated because you have the "Embed interop types" property set to True on the Envox interop library. A new feature in .NET 4.0, extremely desirable because you no longer have to deploy interop libraries or PIAs anymore. It does require you to use a slightly different programming style, you create an object of that COM server with:

  var obj = new Envox.ADXVoice.ADXVoice();

In other words, you use the new operator on the interface type, not the class type. C# programmers tend to blow a gasket when they see this, it is normally completely illegal. But it is accurate, the way COM objects are treated in C# is a bit unusual. It otherwise fits the COM programming model well, you strictly work with interfaces in COM.

You can also set the "Embed interop types" property back to False so you won't have to make any code changes. Bit of a waste, really.

Fwiw, you would probably be ahead by having your C# compiler speak English instead of French. Check this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM