Configuration file for .Net COM when invoked from old ASP - com

there! I have a library written with .Net Framework 4. This library exposes some objects as COM via System.Runtime.InteropServices, which are registered with the regasm utility. These objects are intended to be used by an old (not .Net) ASP page, which is configured under an application that runs .Net Framework 2 (I know!!!) on IIS6 (Windows Server 2003).
Everything seems to work, except for the configuration file. When the .Net 4 COM object attempts to access System.Configuration.ConfigurationManager looking for a connection string, it gets a Null Reference exception. The web site has a Web.config file, and obviously the connection string is there, but the library can't find it. I think that it's because the Web.config is for the .Net applications running under IIS, and the COM library is seen as an external component.
I don't know where else the library might be looking for a configuration file. Changing the machine.config in the FW4 folder works, but I'd like to know if there is another location I could use, because machine.config is system wide and I don't want to pollute that, especially with connection strings. I tried adding a mylibrary.dll.config file in the DLL folder, but it doesn't work either.
Thanks in advance

Related

Accessing a non-COM visible DLL method from a COM visible DLL registered in GAC

My website application uses C# COM+ components running under a particular identity to access SQL Server, invoked from classic ASP.
There's also a web service that utilises a \bin DLL in the website application that contains a method to insert some data into the SQL Server database (let's call it MyApp.Database.dll).
From the website front end, I want to be able to provide authenticated users with this same functionality.
I don't want to duplicate code in MyApp.Database.dll within the COM+ component for obvious reasons.
My idea was to utilise the COM+ component from ASP to invoke the MyApp.Database.dll method to access the SQL database using the application credential since the ASP is running as the user and has no access to SQL Server.
Problem I've seem to run into is that although I can reference MyApp.Database.dll in my COM+ component project (under 'References' and 'using MyApp.Database.dll'), when it comes to actually running or debugging the COM+ component, when it tries to invoke the method from MyApp.Database.dll, it tells me 'Could not load files or assembly 'MyApp.Database, Version=3.3.3.11658, Culture=neutral, PublicKeyToken=.....' or one of its dependencies.'
The MyApp.Database.dll is not registered in GAC (trying to avoid this, it's also used by other applications as well), and hasn't had its codebase registered in the registry using regasm (I tried this and still didn't work). The version is correct, and I've placed MyApp.Database.dll in the application folder of the COM+ component.
Am I missing something or is it not possible to do this?
Thanks in advance for your help.
This is a common mistaken expectation: just because your .NET COM DLL was found in some given folder (the folder set by the /codebase argument or RegAsm) -- it doesn't mean .NET will look on that folder for anything else.
Generally speaking, it won't. Loading a .NET assemblies via COM interop is a special case. For everything else, assemblies will be loaded in the AppDomain based on the Fusion binding policy for the process - which has nothing to do with where your .NET COM DLL is. The process is actually (depending on your version of IIS) either dllhost.exe, iisexpress.exe or w3wp.exe.
You have a few options.
First, the obvious solution is putting MyApp.Database.dll in the GAC, since .NET always looks there. Sometimes that's the right choice (I've done that and it works). You have declined to do so and you have your reasons; that's Ok.
Second, I believe you can change the binding policy with a web.config file. See here: http://msdn.microsoft.com/en-us/library/823z9h8w(v=vs.110).aspx. Yes, your ASP Classic project can have a web.config. Obviously it has no effect on your ASP Classic scripts, but (depending on the version of IIS), .NET and/or IIS itself use it for configuration. I'm afraid that I can't help you much with this alternative because I've never had to try it before, but you're welcome to explore that option - let me know how it goes.
Third option - my personal choice: You said this DLL is already a web service, right? Just call the functionality with a web service call from your COM DLL. That doesn't require mucking with magic folders, GAC and binding policies. Much cleaner. The only mild complication is tracking in configuration where your web service is located - and I bet you already do that for your database connection anyway, so it shouldn't be hard to add.
If you are curious to know where .NET is looking for the DLL, read up on these guys:
How to enable assembly bind failure logging (Fusion) in .NET
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx
http://www.hanselman.com/blog/MoreOnAssemblyBindingStrongNamingTheGACPublisherPolicyAndDynamicallyLoadedAssemblies.aspx
Good luck, and please let us know what worked for you.

Use an unregistered COM dll in Classic ASP

I have a strange situation and I am unable to find a solution for this. I am working on a publically accessible Classic ASP site. I don't have access to the server or IIS but I have FTP access to it.
Now I want to reference a COM dll (not a .Net dll) to one of the asp pages. And then use it to create objects like:
Server.CreateObject(...)
I know about using RegSvr32 to register the dll or placing it into C:\Windows\system32, but I am unable to do so as I don't have access to the server.
I tried to place the dll with the asp file but it did not work.
Is there any other way to make it work?
I understand the situation, and have been there before.
However, there is no way (that I am aware of) to get it done that isn't related to a security/setup flaw that would make me want to change my hosting provider.

Consuming SharePoint 2010 WCF from .Net 4.5 + Store portable class library (PCL)

Can VS2012 build a proxy in a PCL project to consume a WCF service for SP2010? We add a reference (old school works everywhere else) but once we make calls, for instance GetListsCollectionAsync(), we get all sorts of errors. When we build the proxy, VS gives a warning:
Service proxy generation failed. Proxy requires type 'System.Xml.Linq.XElement' which is not supported in portable libraries
Has anyone successfully subscribed to a SharePoint WCF using a portable class library? The same stuff works fine in .net 4.5 class libraries and in metro libraries. Only portable ones give us this problem. We have win 7 and win 8 devices in the mix - so PCL would be a really good fit.
Got a conclusion here: We found a work around and the statement that this is a bug in VS2012 PCL projects still stands.
We created our proxy in a metro project and simply copied the reference.cs file over into the PCL project. It was a "what the heck - why not" last attempt of sorts, but it actually works. Even better, the calls are awaitable and come with response objects. Awesome!
Cheers,
Gregor

Monotouch Web Reference Namespace Issue

I have an ASP.net web service sitting on a server, and I have verified that it works properly via a small test client app in VS.
I went to add it in MonoDevelop to my MT application, (Trying both the ASP.net 2.0 and WCF declarations). Inside the "Add Web Reference" wizard, it finds the web service fine. But when I go to reference it, the app doesn't know it exists.
I went to look at it, and it seems when adding it, the namespace it's assigning to it is the title of my solution (which has spaces in it), but the namespace for each of my .cs files within my app contains no spaces.
Web Service Namespace (that it wont let me change): Ultimate GameDay 2011
MT Application Namespace: UltimateGameday2011.
So I manually went into the reference.cs file and took out the spaces. The app classes then saw my web reference object, but it still won't allow me to access any of its members.
Any help would be greatly appreciated.
Check out the following link http://merbla.blogspot.com/2011/03/monotouch-with-json-using-aspnet-mvc.html
Its not a fix to your problem rather a method of creating web services that MonoTouch more easily works with. In my experience ASMX and WCF services have been problematic when consuming in a Monotouch app.
If all else fails, try using the Silverlight service utility located in your programs folder
e.g. C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Tools\SlSvcUtil.exe

WCF web service fail run from the IIS because could not load DLL?

I wrote some WCF application.
I registered the application on the IIS.
The WCF application is build by using some dll that i wrote in the past.
I created reference to them and its seems that all work fine when i start the application thru the visual studio 2010.
But when i run it thru the IIS - i get message about some DLL that missing - even if the DLL it clearly in the project.
What i can do to fix it ?
I remove the reference - and load it again - and still nothing help.
Thanks for any help.
Is the DLL/Reference marked as Copy Always in properties? This will force the DLL to copy to the bin folder which IIS will require for a non-GAC'd assembly