Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Archive for August, 2011

Interop type cannot be embedded. Use the applicable interface instead

Posted by Viral Sarvaiya on August 2, 2011

Today i face one more difficulty in my current project,

i am useing .net 4.0 framework with WPF application.

In this application i am adding one dll file that communicate with COM port and i get error “Interop type cannot be embedded. Use the applicable interface instead.”.

this code is perfactly run with .net 3.5 framework but not in 4.0.

and i get the solution for that as below.

Common Language Runtime in .Net 4.0 supports embedding of COM types information directly into managed assemblies in order to simplify deployment process. Managed assemblies need not have to read type information from interop assemblies any more.

In the managed assembly  you can embaded only COM type metadata so it will only works with interfaces, structures, enums and delegates

so what to do for this problem? the solution is “use interfaces instead of classes” or “simply copy constant values from the class definition locally and use them instead.”

hope this will helps you..



Posted in .Net, feature | Tagged: , , , , , | 5 Comments »

Check printer status in .net

Posted by Viral Sarvaiya on August 1, 2011


Today i get new thing from my current projet, how to check the status of the printer means wether the printer is connected to PC or not.

For that we have to add reference of the “System.Management”

Here it is code for check status of the printer.

using System.Management;

class PrinterOffline
private static void Main(string[] args)
// Set management scope
ManagementScope scope = new ManagementScope("\\root\\cimv2");
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string printerName = "";
foreach (ManagementObject printer in searcher.Get()) {
printerName = printer("Name").ToString().ToLower();
if (printerName.Equals("Name_Of_Printer")) {
Console.WriteLine("Printer = " + printer("Name"));
if (printer("WorkOffline").ToString().ToLower().Equals("true")) {
// printer is offline by user
Console.WriteLine("Your Plug-N-Play printer is not connected.");
} else {
// printer is not offline
Console.WriteLine("Your Plug-N-Play printer is connected.");


thanks and enjoy coding…

Posted in .Net, ASP.NET, feature, Visual Studio, WPF | Tagged: , , , , , , , | 6 Comments »

%d bloggers like this: