Thursday, November 1, 2007

Automation Error System cannot find the file specified

You might run it to this problem when you are trying to load a COM exposed .net component from a COM application such as VB. The problem is that the COM is not able to find your component in the registry. Here are some of the resolutions you can try

- Enable Register for COM interop in the project properties window

This use to be enough in .Net 1.1 /VS 2003 to get the component registered. But in .Net 2.0/VS 2005, Microsoft introduced another way to specify the COM visibility. That is by introducing a new attribute [assembly: ComVisible(true)]. Add this attribute to your AssemblyInfo.cs file and recompile the project.

If you are still having the problem, try registering the component explicitly using

regasm c:\abc\abc.dll /tlb

sometimes the /tlb option does the trick.

If this doesn't fix the problem check the version number of the component on which your component depends on. If the components, on which your component depends, are singed with specific key and are of specific version, then your component also need to be signed with the same key and versioned the same. Otherwise you will get the same automation error when loading from the component from a COM client. In .Net2.0 you update the AssemblyInfo.cs to update the version number and sign the component

e.g.

[assembly: AssemblyVersion("x.x.x.x")]
[assembly: AssemblyFileVersion("x.x.x.x")]

[assembly: AssemblyKeyFile(@"your_key.snk")]

Hope this helps.

Tuesday, September 11, 2007

Accessing network resource with in a Windows Service

Recently I ran into this problem where my windows service running under local system account could not access network resources such as shared folders. After googling a bit, I found Microsoft article that recommended running the service under "Network Service" account instead of System account when the service requires access to network resources. That sounds reasonable.

After applying the changes run my service under Network Service account, I realized that now my service cannot access local files. That means the services running under Network service can only access network resources but not local resources. I am not sure what's the motivation behind it though.

Next I tried creating a user defined account with the permission to access files both locally and remotely. I made my service to run under this new account. But still the service is not able to access network resources.

If I convert the service to a standalone EXE and run it, it is able to access network resources.

I have two more solutions to try. One of which is to update the windows service to impersonate another user through the code. Another solution is to map the driver within the service before accessing such drives. I am not sure how this might work out, I will keep you guys posted.

If you have a solution, your input will be much appreciated.

Tuesday, July 24, 2007

warning MSB3214: "*.dll" does not contain any types that can be registered for COM Interop.

Sometimes when a .Net assembly is made COM visible, you might still see MS Visual Studio 2005 complaining

warning MSB3214: "*.dll" does not contain any types that can be registered for COM Interop.

We know we can make a assembly COM visible by

  • adding [assembly: ComVisible(true)] in AsseblyInfo.cs
  • specifying [ComVisible(true)] attribute for the classes that need to be made com visible
  • and also checking the "Register for COM interop" option in project properties window under Build tab

After all these changes you might see Studio still not able to create the TLB for the assebly. In other words not able to register the assebly for COM interop.

Resolution:

I have not found the actual cause of the problem. But following workarounds have fixed the problem

  • Somtimes closing the project and then reloading fixes the problem.
  • Open the command prompt and try registring the component with regasm command. Makre sure you are using the /tlb option. Without it you would get RegAsm : warning RA0000 : No types were registered

The command would look something like

C:\Program Files\Microsoft Visual Studio 8\VC>regasm asseblyname.dll /tlb

If someone knows the actual cause please let me know