I created a console application to import "C" Dll using DllImport
The "C" Dll has reference to other Dll's and Config files in same folder.
When i put all the files in bin directory of Console applicaiton it works perfect.
But when i create a Web application to consume the same it does not work. (The dll reference are fine when i set the path, but it seems the config files are not getting loaded)
I have tried below but did not help.
Copy the DLL's and config files to System32.
Give access permission to IIS.
Disable shadow copy.
None seem to work, Any other suggestions?
I solved the issue.
I used Directory.SetCurrentDirectory(); to set the path of the dll's and config files.
if its not possible to change the current directory. Place the files in path Directory.GetCurrentDirectory();
You'll need to move the configuration into the web.config file for the web application
There's some good advice on how to do that here: Custom section/collection in Web.Config
Related
We have an ASP NET Core 6 API application hosted on Azure App Service.
Together with the application we would like to deploy some external xml files that are used later on by the backend runtime. We have added them to the project and set CopyToOutputDirectory = true.
Have to questions:
How to access these files from code in safe way?
What we tried is
Assembly.GetExecutingAssembly().GetName().CodeBase)?.Substring(6) to get base path but it looks hacky.
_webHostingEnvironment.ContentRootPath but it returns wrong location in development (project root folder instead of /bin)
using relative path Path.GetFullName("file.xml") but it returns project root folder in development as well
We saw that there is another property that can be set on file called CopyToPublishDirectory. When it should be set? We set only CopyToOutputDirectory and it seems to work also when doing dotnet publish. Any reference?
Let's approach this problem in a different way. When we publish the project, we include the bin folder in the publish file. Then you can access .xml inside the bin folder.
Show all files and include to your project.
Open .csproj file and modify it.
And your csproj file should be like:
https://dotnetfiddle.net/qG3W8h
comment out this paragraph and add CopyToOutputDirectory, like below:
https://dotnetfiddle.net/jrccnJ
Then you can deploy it, then you can find the bin folder.
Then you can access the file gracefully.
I Created a WCF Service and added a dll file as a reference and i am getting the error mentioned in the title during runtime.
Created a WPF application and added the same dll file as a reference but it worked.
The dll file has other references that i added manually in the bin/debug folder of the wpf app.
When i try to do the same for WCF service it is not working.
Please help me figure it out.
I am new to C#. Unfortunately no one answered it, i found solution myself after three hours :(.
A dll file will always be used by an exe file.
In this case the exe was in the folder C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0 which is the folder for ASP.NET development server.
So the dependent dll files need to be copied there. Copying to the bin folder will not work.
Well, this question is a bit different from others with the slightly same title.
I add a config file to my DLL which will be used from a website and a console application.
I'm testing the DLL from my web application.
When I build the DLL I can see my MyApp.dll.config in the bin\debug folder.
Nevertheless, when I try to read the settings from the DLL this way:
var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
The file is not found.
I know it is something to do with the location where the application is being executed as Assembly.GetExecutingAssembly().Location return a path in Framework\v4.0.30319\Temporary ASP.NET Files\root\... while AppDomain.CurrentDomain.BaseDirectory return another completely different path.
So, what I'm doing wrong? There is some configuration missing to get the config file to be copied in the real location where the application is being ran?
Thank you in advance from your help!
Usually when you build a .dll and it has a config, that file lives with the dll in the same folder.
Alas, when you use your dll in another project, that project usually has it's own config, which takes precedence over the dll's one.
You could either add the dll's config to the parent's config, or try configuring what you need in code, instead of in the config.
In .NET DLLs can not have configuration files. They will simply not be used. They are created if you use the settings tab in the project properties, but they will not be read. What you need to do is merge the settings from that config file into the application's configuration (in your case, the web.config file).
I am working with developing Windows Service using C#. I want to load CLIPSLIB.dll with Windows Service. First I tried write service as console app in vs2010 placing CLIPSLIB.dll in the project debug folder. It worked fine.
But when I install it and run as Windows Service it throws this exception.
Could not load file or assembly 'Mommosoft.ExpertSystem, Version=0.3.0.2, Culture=neutral, PublicKeyToken=20382083c6694bdc' or one of its dependencies. The system cannot find the file specified.
As I figured out this is happening because Windows Service is unable to load relevant dlls. So whare should I put external dlls to load with Windows Service?
Scott Hanselman has an article that describes how to debug assembly loading errors. the downside to this method is that it requires a registry key change and a reboot in order to emable the fusion loader logging.
That article can be found here:
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx
since you are writing a windows service check that the reference for the assembly refers to the bin directory and not some other path. Otherwise the fusion loader logs will identify where it is trying to load the assembly from.
as to the .dll files add a folder to your project and add the .dll files there, change the build properties from do not copy to copy if newer in order that the .dll files will end up in your build output bin path.
You must rebuild the CLIPSLib solution,
Download all files in this link :
Link: https://svn.code.sf.net/p/clipsnet/code/
2.Open CLIPSLib.sln in CLIPSLib folder
3.Right-click on the solution and select rebuild solution.
4.Go to the CLIPSLib folder your CLIPSLib.dll and CLIPSNet.dll is in ..\ ..\mlplatform\bin floder.
hope this help.
I'm a bit lost!
I have a dll that uses an xml config file for some db connection info. The dll looks for the xml config file in it's own directory and I can't change the dll at all.
Every time I build the project, I must manually copy the config file into a folder way down somewhere in the Temporary ASP.NET Files folder. (I don't understand this but I can live with this manual change)
The problem is that when I publish the project, I can't figure out where to copy the config file to?
Could someone please point me in the right direction? Or maybe show me a way that I can 'bind' the xml config file to the bin folder???
Vauneen
The .NET config file can be confusing to manage. The way it works in a webapp is that the Web.config will supersede any dependencies' app.config files (which is what I assume you're talking about when you say "DLL".)
Basically, in .NET all config info is pulled from the main app project.
See:
App.config seems to be ignored
and
Configuration from App.config isn't being pulled correctly
and finally:
Does a web.config substitute app.config?
will probably help you figure out what you need to know.
Update: Doing some further searching on your problem, it's possible that the code you're incorporating into the .Net Solution is using the "obsolete" ConfigurationSettings which will require you to add a reference to System.Configuration in your references folder (right-click on the project -> "Add References" and go to the .NET tab and select System.Configuration).
Set "Copy to Output Directory" to "Copy always" in properties of the configuration. Then Visual Studio will copy the configuration file automatically after each build and it will be properly published as well.