3rd Party .Net Assembly not working in WebService project - c#

So I'm trying to use a .Net Assembly in my web services project. This assembly requires lots of settings in App.config. But my web service doesn't have an App.config, it has a web.config. It seems that it uses sections that an app.config would have that don't even exist for web projects. Is there any way I can make this assembly work? (make it read another config file maybe?)

You should be able to simply use the same configuration sections in the web.config file that exist in the app.config and it would work.
The way the configuration subsystem works means that it does not matter.

Related

Is it good practice to place Service Reference when consuming WCF in library(.dll) project?

I have to consume a WCF Service. I have multiple layers in my project. I have one output project and other are library projects. All are dll projects except one output project. I would like to know the best place to place my service references. This is one serious architecture related concern that I want to understand.
The best thing that I found is that App.config or Web.config are placed in output projects. I should add service references in output project only because it is it generates bindings and other endpoint details in config file only. I will be required to copy paste all the things in output project only if place it in dll projects.
You need to copy the WCF configurations into the main web.config or app.config project. Whatever the executing program is. Referenced here: Cannot call WCF WebService from DLL
Or don't use configurations at all, do it programmatically like here: WCF Configuration without a config file

web.config in ASP.NET 5 MVC 6

I have a WCF .dll that loads configuration from web.config file.
I'm using that dll in asp.net 5 application, when I try to call a function from dll, I'm getting exception:
Could not find default endpoint element that references contract 'WebService.MyWebService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
The configuration for dll exists in web.config.
This used to work in asp.net beta 6, but now that I upgraded to rc1 it doesn't work.
How can I make this work?
As stated here:
Support for app.config when running on the full .NET Framework
When running on the full .NET Framework you can now use System.Configuration to access configuration data in app.config from a DNX based console application. Simply put your XML configuration file next to your project.json file.
So I only had to copy contents of web.config to app.config

External dll is referencing current project's web.config

I've got two projects, WebAPI project as A and MVC4 project as B.
The dll of A project is referenced in B project.
I found that A's dll is using the config setting in B's web.config.
These projects have different definition for corresponding web.config.
So how can I do A's dll to use its own web.config and not to use B's web.config?
The configuration file is read only from starter project. You can merge configs if they differ in appsettings or connectionstrings. But if they differ in system settings like .net version, authentication and so on, you should launch your projects separately.
You're doing strange things, because MVC4 has initial support for WebApi. You can extract business logic from WebApi into another project. Do you really need to have WebApi controllers in separate project?

Cannot find .config file for a dynamically loaded 3rd party assembly used by ASP.NET Service

C#, VS2010, .Net 4.0, ASP.NET service under IIS or IIS Express.
I'm using a 3rd party assembly within my service. This 3rd party assembly has a .config file and is loaded dynamically as such:
Service -> MyAssembly1 -> Dynamically Load MyAssembly2 using Assembly.Load() -> 3rd Party Assembly with .config
I'm normally a C++ developer so this ASP.NET stuff is rather new to me.
I understand that with an ASP.NET application the assemblies it uses are "shadow-copied" to the Temporary ASP.NET Files folder.
Unfortunately when this 3rd party assembly is "shadow-copied" its .config file is not. So when it comes time to use this assembly it's failing because it cannot open its .config file.
From within my assembly I'm able to get the CodeBase for that assembly and load the .config file myself, but that doesn't help me since this 3rd party assembly needs to open the file itself.
If I manually copy the .config file to the shadow-copy location it works great.
Also, this 3rd party called the config file "assemblyname.config" instead of "assemblyname.dll.config".
The error I get is:
Unable to load configuration file: "\assemblyname.config".
When this 3rd party assembly is used in a non ASP.NET app (ie a normal Windows app) it works great since it doesn't do the shadow-copy stuff. Just uses the assembly and .config file directly from the exe location.
Any ideas? I've been unable to find a solution though I'd think this would be a rather common issue.
The main thing when loading assemblies is to see the path where the assembly is placed on disk and the page directory from which you are trying to load the assembly. So if you are adding the path for loading the assembly that does not mean that from the same path it will load the config file. Please try to put them both in the root folder of the app and see if the issue remains.

App.config not located by a .net assembly

I have an ASP.NET application which is adding up .NET assembly in its reference. The assembly is a private assembly and it has a config file with some keys under <AppSettings>.
Now the problem is when I am debugging my ASP.NET application the assembly is not loading the app.config file.
I observed that under the property of referenced assembly I have Copy Local=true.
Can anyone please help or point out if i am missing some basics?
You need to collect all pertinent settings into the web.config file of the main ASP.NET application. Only the config file of the running application (be it web or desktop) is loaded automatically.
Look up some articles on how config files work in the .NET environment to learn the basics of what is and isn't loaded, it'll definitely help you avoid headaches like this in the future.
Alternatively, if you know the name of your assembly's config file you can add a file attribute to your <AppSettings> element, pointing to that file if it's copied to the same directory as the web.config is in.
<appSettings file="privateassembly.config">
Please note that any appsetting with the same name declared in the web.config will be overridden by the privateassembly.config. Also note that any change to privateassembly.config (while the ASP.NET application is running) will not reset the application pool and thus will not be loaded into the AppDomain.

Categories