LINQPad and <connectionStrings configSource="..." /> and error 80131904 - linqpad

Recently I've changed all .config files in our family of .NET projects to share the common DB connectivity:
<connectionStrings configSource=".\connectionStrings.config" />
where connectionStrings.config is supplied by pre-build event.
It seems to me that LINQpad 4.55.03 (Premium edition) does not support such kind of connection string externalization - it needs embedded connection string definition.
The file connectionStrings.config is on the path set in LINQPad's propeties, it is also copied to target bin folder where .dll with DB Context resides, LINQpad's connection test has succeeded, LINQpad is able to list entities from DB, but no query can bee executed at all - the result is error 80131904.
I got around by using linqpad.config, copying section with real definitions there. I had to clear path to config file in the connection properties.
Is there a way to refer app.config as I did before or is linqpad.config only way to make it running?
Thanks, pf

Yes, you must use LINQPad.config.
LINQPad.exe.config is for the LINQPad GUI.
LINQPad.config is for your queries.
When you test a connection that loads custom assemblies, LINQPad should use the LINQPad.config file. It sounds like it's using the LINQPad.exe.config in your case. What kind of connection is it?

Related

Reference VB.NET DLL in Kofax Document Validation Script

We are working on a validation script for Kofax Capture 9.0 / 10.0 in VB.NET 3.5.
We know how to create a script using the Admin Module, and how to get it operational.
The problem is that we need to reference a dll, located on a remote machine. (GAC is no option) This dll holds abstract classes we need in each validation script.
Even when putting the dlls locally (copy local), the Validation Module (index.exe) immediately throws the "cannot find reference" exception, even though the project compiled perfectly.
I guess the basic question comes down to: where do we put the dlls, in order for the Validation Module to find them?
The simple answer is to put the dll in the same folder as the application because this is one of the places which .NET will probe when trying to find it. The Validation module is run from the Capture bin directory which will be something like "C:\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\". This would need to be done on each client using Validation.
If you have a more complicated scenario, you could look implementing the AppDomain.AssemblyResolve Event and using Assembly.LoadFile to get the assembly from a custom location, but the using the bin path is less complicated.
If you end up having further trouble, you can troubleshoot by using the Assembly Binding Log Viewer (Fuslogvw.exe) which can tell you more details about why the assembly failed to load and where .NET tried to search for it. Assembly loading can fail for reasons other than just the path.
For more detail on how .NET loads assemblies, see the following:
How the Runtime Locates Assemblies
Locating the Assembly through Codebases or Probing
We found a solution: add all library files as "links" to the project. (Add --> Existing File --> small arrow next to "Add" --> Add as Link)
This ensures the files are compiled when you build the project. The Kofax Validation Module can now find the files, whereas when referencing the file, it could not. Why it could not, remains a mystery...

Missing app.config file?

I just inherited a VB.Net application that gets a SQL connection string like this:
Dim m_GMSConnString As String = System.Configuration.ConfigurationSettings.AppSettings("connString")
But there's no app.config file in the solution/project. So where is it reading from?
EDIT: If this is a DLL project and the DLL is then referenced by a website project, will the DLL read from the web.config of the website project? That's the only explanation I can come up with.
EDIT: If this is a DLL project and the DLL is then referenced by a
website project, will the DLL read from the web.config of the website
project? That's the only explanation I can come up with.
From my experience (and it is confirmed here Why wont my application read my MyApplication.dll.config file?) answer is yes, the code will only read the app.config of the main project (or web.config in your case).
But the answer also provides link that show how to use multiple config file. I think you can tell your program to read some part from external file (your dll.config file in your case).
if I remember correct, there is a config file with the same name as the exe file but add the extention of .config, such as yourprog.exe.config

Entity Framework Context Not Working

I am trying to figure out Entity Framework but I keep running into issues with the context. I create my .edmx file and it works fine but when I try to declare my context on my pages Visual Studio will not find them. My .edmx file is called YCLModel.edmx and my connectionstring for it is YCLEntites.
I try to declare the context as:
Dim yclcontext as new YCLEntites
I have also tried going into design mode and dragging from the toolbox but when I select my named connection it gives me the following error:
The metadata specified in the connection string could not be loaded.
Consider rebuilding the web project to build assemblies that may
contain metadata. The following error(s) occurred:
Unable to load the specified metadata resource.
Do you have your .edmx file defined in a separate project other than your web project? If so, you should copy the connection string data from the app.config of your project to your web project.
The issue was the edmx file was in the app_data folder.

How Do I Use the app.config file with a Test Project

I using unit testing, to ensure that I can read connect string information from the ConnectStrings section of my app.config file. This works fine in the application proper, However when I attempt to generate a unit test for this under the Test Project, the dll.config file is being ignored, and the connectstring info from the machine.config file is being retrieved instead. How do I ensure that my tests read from the correct config file?
Your test project must have its own App.Config file.
You should add an app.config file to to your test project and populate it with the necessary values. You may ask "Why can't I use the existing app.config in my project?" The real answer is probably out there but personally I like it this way because it means my test project never points at my production environment.

Why is nhibernate looking in /bin/debug for the hibernate.cfg.xml?

I have a class library with all my nhibernate code (domain/mappings using fluent).
Now I am just doing some simple tests in a console application, and I am getting an error saying it can't find the configruation file in /bin/debug
I have the file in /consoleTests/hibernate.cfg.xml
Why would it be looking in the /bin/debug folder of the console application?
If you are calling the Configure() method without any parameters, then I believe that the hibernate.cfg.xml must be in the same directory as the application that uses it.
When you compile your project, it gets compiled to the bin/debug/ directory. When you run your project (by either clicking on it or debugging it in Visual Studio), the working directory is bin/debug/, so that is where the hibernate.cfg.xml file is expected to be.
You could:
use a post-build event within Visual Studio to copy the hibernate.cfg.xml file to the output directory
call Configure(path), where path is the path to your hibernate.cfg.xml in your /consoleTests/ directory.
Have a look at "A fluent interface to NHibernate - Part 4 - Configuration" for more detailed information on how to configure NHibernate.
You can set the xml property "Copy to Output Directory" to "Copy Always"
That's the current directory when running in Visual Studio. Is that what you're doing?