iTunes comes with an api you can access from any (.NET) program by adding the COM reference “iTunes 1.xx Type Library” (see iTunes COM for Windows SDK) to your Visual Studio project:
using iTunesLib; iTunesApp app = new iTunesAppClass();
When trying to instantiate an ‘iTunesAppClass’ object the compiler initially outputs the following error message, although creating an instance of this class is the only way to access iTunes:
“Interop type ‘iTunesLib.iTunesAppClass’ cannot be embedded. Use the applicable interface instead.”
This is due to a setting in the reference properties:
- Go to the Solution Explorer.
- Right click on References –> iTunesLib and hit Properties.
- Set “Embed Interop Types” to False.
This solves the described error and you can go on automating iTunes.
Remarks: For German localization settings the error message is “Der Interoptyp “iTunesLib.iTunesAppClass” kann nicht eingebettet werden. Verwenden Sie stattdessen die entsprechende Schnittstelle.”
Anna Chiara
Thank you so much! I’m a COM/C# newbie and you’ve really helped me!
Mark Thomas
This did not resolved things for me in a recent version of .Net. However, removing ‘Class’ from the name did. See: https://stackoverflow.com/questions/2483659/interop-type-cannot-be-embedded
“In most cases, this error is the result of code which tries to instantiate a COM object. For example, here is a piece of code starting up Excel:
Excel.ApplicationClass xlapp = new Excel.ApplicationClass();
Typically, in .NET 4 you just need to remove the ‘Class’ suffix and compile the code:
Excel.Application xlapp = new Excel.Application();”