My question falls under the category "I have written an application that
works fine on my developer machine, but throws a SecurityException on all
other computers". I spent almost the entire day reading through the
information already available on this topic. I now have a basic understanding
of code access security in .NET, the CASPOL tool, the TBLIMP tool, strong
names and signed assemblies. However, I still haven't been able to solve my
problem, and I'm close to giving up.
The application I wrote references Interop.DSOFramer (for embedded Office
documents) and Interop.WMPLib (for embedded Media Player), as well as the
corresponding ActiveX controls AxInterop.DSOFramer and AxInterop.WMPLib. In
addition to that, it also uses an SQL 2005 Express database, accesses the
Windows registry and needs write access to the file system. I'm using Visual
C# Express on Windows XP with .NET Framework 2.0 SDK
Here is what I did so far...
* I learnt that the host system needs to grant access to the application's
features (I develop it in a fully trusted environment) in order to be run on
other client's machines. I tried using CAPSOL as part of my installation
tool, but politely got informed that my application does not have a strong
name, which is required.
* I further learnt that, in order for my application to receive a strong
name, it needs to be signed with a strong name key file. I created a new
keyfile in the project's "Signing" properties (I also successfully tried
creating one with sn.exe) and configured the app to be signed. I then
received a notification that the signing failed because the referenced
interop assemblies mentioned above do not have a strong name.
* I searched the Microsoft's website for strong named versions of the used
assemblies, but couldn't find any. According to a MSDN KB article, the only
other option I have in this case is to link the interop assemblies with my
own keyfile. Unfortunately, the solution posted for Visual Studio .NET 2003
didn't help me, because the "Wrapper Assembly Key File/Name" options do not
seem to exist in Visual C# Express.
* I have not yet attempted to use the TLBIMP tool with the COM DLLs in order
to generate signed interop assemblies.
So here I'm stuck with a cool app that can't be signed, thus not trusted,
and therefore doesn't work anywhere else. How can I make my application (with
all its security sensitive features and requirements) run on a computer other
than my own? Surely, there must be a very simple way to accomplish this, but
I just don't see it. I'm all in for strong .NET security, but this has been a
really frustrating developer experience so far. I want to finish this app,
wrap it into an installer and be done with it - without complicated system
configuration steps on the user's end (i.e. to lower .NET security settings,
add code access groups etc).
Any help would be highly appreciated.
~Max
Gerke M. Preussner - 18 Nov 2006 04:30 GMT
I solved the problem.
For the DSOFramer library (Microsoft Office control) i generated a signed
type library using:
tlbimp lib/dsoframer.ocx /keyfile:FST2Kiosk.snk /namespace:DSOFramer
/out:lib/dsoframerpia.dll
Source code for this control is included with the download, so I think it
should be possible to build a strong named library from within Visual Studio
.NET 2005 (I only have 2003 right now, which doesn't support the new security
features yet, so I can't test it). In that case you shouldn't have to use
tlbimp.
For the WMPLib library (Media Player control) I actually found a PIA in the
Media Player 9 SDK. It is not included in the version 10 SDK.
You have to register both type libraries and add them to the global assembly
cache, so that Visual Studio can find them:
regasm dsoframerpia.dll
gacutil /i dsoframerpia.dll
regasm wmppia.dll
gacutil /i wmppia.dll
You have to remove existing controls from your form and add them again.
Visual Studio will then automatically detect the strong named wrappers.
The locations of tblimp.exe, regasm.exe and gacutil.exe depend on where you
installed the .NET Framework and Visual Studio. You might want to add the
paths to the environment.
Regards,
GMP
Gerke M. Preussner - 18 Nov 2006 04:33 GMT
PS: Please note that you have to replace all paths and the name of the key
file with your own. For the key file I used the one I generated for my
application.
aleem076@gmail.com - 11 Jan 2007 09:29 GMT
Sir,
After I register the dll file "d:\Aleem\DSOControl1\DSOControl1.dll" I tried to install it in gac, but it is giving erro as
*Failure adding assembly to the cache: Attempt to install an assembly without a strong name*
could you please tell me whats wrong with me.
Regards,
Aleem.
aleem076@gmail.com - 11 Jan 2007 09:39 GMT
Sir,
After I register the dll file "d:\Aleem\DSOControl1\DSOControl1.dll" I tried to install it in gac, but it is giving erro as
*Failure adding assembly to the cache: Attempt to install an assembly without a strong name*
could you please tell me whats wrong with me.
Regards,
Aleem.