google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

DbLinqProvider is loaded using the wrong assembly load context; uses Assembly.LoadFrom(), not Assembly.Load(). #213

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use DbMetal with MySQL as provider
2. Import generated cs-file into project together with DbLinq.dll,
DbLinq.MySql.dll and MySql.Data.dll.
3. Make a query

What is the expected output? What do you see instead?
Could not load file or assembly '...\IDE\DbLinq.SqlServer.dll' or one of
its dependencies. The system cannot find the file specified.

What version of the product are you using? On what operating system?
DbLinq 0.19

Please provide any additional information below.
How come the DbLinq.SqlServer.dll is need when using MySQL?
Even if I make a reference to DbLinq.SqlServer.dll I still get the above
reference error :-(

Original issue reported on code.google.com by Rasmus.C...@gmail.com on 16 Mar 2010 at 2:28

GoogleCodeExporter commented 9 years ago
What operating system are you using? and how do you perform the query (i.e. 
what does
your connection string look like and how do you construct the database 
context)? One
reason that DbLinq might want to use SqlServer is if you didn't tell it to use 
MySql
instead of the default (which is SqlServer).

Original comment by anders...@gmail.com on 16 Mar 2010 at 2:55

GoogleCodeExporter commented 9 years ago
On this platform I running on Windows 2008 Server x64.
My ConnectionString: 
<add name="web406135ConnectionString"
connectionString="DbLinqProvider=MySql;Server=aaa;Database=bbb;Uid=ccc;Password=
ddd;MultipleActiveResultSets=True;"
/>

I have resently changed the connectionstring to the above, as before I didn't 
include
the DbLinqProvider-section. I have looked for connectionstrings to MySQL but 
only
found generic MySQL connectionstrings, so I didn't knew that I was missing this
section :-( Anyway now it has been corrected, but I still get the error :-(

Example of code, just to make an intial working sample:
public static int UserCount()
    {
        int counter = 0;
        using (Web406135 context1 = new
Web406135(ConfigurationManager.ConnectionStrings["web406135ConnectionString"].Co
nnectionString))
        {
            var userProfileCount = context1.UserProfile.Count();
            counter = Convert.ToInt16(userProfileCount);
        }

        return counter;
    }

The complete error description:
 Could not load file or assembly 'file:///c:\Program Files (x86)\Microsoft Visual
Studio 9.0\Common7\IDE\DbLinq.MySql.dll' or one of its dependencies. The system
cannot find the file specified.
Description: An unhandled exception occurred during the execution of the 
current web
request. Please review the stack trace for more information about the error and 
where
it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or 
assembly
'file:///c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll' or one of its dependencies. The system cannot 
find
the file specified.

Source Error:

Line 34:    #endregion
Line 35: 
Line 36:    public Web406135(string connectionString)
Line 37:        : base(connectionString)
Line 38:    {

Source File: g:\# 
Websites\profile-metaverse.net\App_Code\ProfileMetaverseContext.cs
   Line: 36

Assembly Load Trace: The following information can be helpful to determine why 
the
assembly 'file:///c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll' could not be loaded.

=== Pre-bind state information ===
LOG: User = TECH-T500-RCH\Administrator
LOG: Where-ref bind. Location = c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll
LOG: Appbase = file:///G:/# Websites/profile-metaverse.net/
LOG: Initial PrivatePath = G:\# Websites\profile-metaverse.net\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will 
only be
probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL file:///c:/Program Files (x86)/Microsoft 
Visual
Studio 9.0/Common7/IDE/DbLinq.MySql.dll.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'file:///c:\Program 
Files
(x86)\Microsoft Visual Studio 9.0\Common7\IDE\DbLinq.MySql.dll' or one of its
dependencies. The system cannot find the file specified.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence
assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean
throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence
assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean
throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence
securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean
forIntrospection, StackCrawlMark& stackMark) +83
   System.Reflection.Assembly.LoadFrom(String assemblyFile) +32
   DbLinq.Data.Linq.DataContext.GetVendorInfo(String& connectionString, Assembly&
assembly, String& typeName) +238

[ArgumentException: Unable to load the `DbLinq.MySql.dll' DbLinq vendor within
assembly `MySql'.
Parameter name: connectionString]
   DbLinq.Data.Linq.DataContext.GetVendorInfo(String& connectionString, Assembly&
assembly, String& typeName) +329
   DbLinq.Data.Linq.DataContext.GetVendor(String& connectionString) +54
   DbLinq.Data.Linq.DataContext..ctor(String connectionString) +128
   Web406135..ctor(String connectionString) in g:\#
Websites\profile-metaverse.net\App_Code\ProfileMetaverseContext.cs:36
   UserProfile.UserCount() in g:\#
Websites\profile-metaverse.net\App_Code\UserProfile.cs:41
   Page_test.Page_Load(Object sender, EventArgs e) in g:\#
Websites\profile-metaverse.net\Test\RCH\test.aspx.cs:39
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t,
EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs
e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +627

Original comment by Rasmus.C...@gmail.com on 16 Mar 2010 at 3:18

GoogleCodeExporter commented 9 years ago
Thanks a lot for the detailed information.
It seems that after you've changed the connection string, DbLinq is searching 
for the
DbLinq.MySql.dll as excepted. Have you placed that dll in the same folder as the
DbLinq.dll? It seems to be a asp.net webapp, so I assume that that dll and its
config-file is in the bin-folder of the web application, although I have not 
tested
if this works myself.

Original comment by anders...@gmail.com on 16 Mar 2010 at 5:21

GoogleCodeExporter commented 9 years ago
DBLinq.dll, DbLinqMySql.dll and MySql.Data.dll are placed in the bin folder and 
I can
'access' the methods etc. from those files. 

What config-file are you talking about? The only config-file I have knowledge 
about
is DbMetal.exe.config, and I guess that is only used by DbMetal when creating 
the
class file from the database, or am I wrong?
That config-file can't be placed in Bin nor in App_Code where my classes for the
website are located.

I have d/l the src file and can find no config-file in the MySql sample so I 
guess
that no config-file is needed or am I mistaken here? If there is a need for a
config-file, where do I find it and where should I place it?

Original comment by Rasmus.C...@gmail.com on 17 Mar 2010 at 6:51

GoogleCodeExporter commented 9 years ago
Times like this make me glad I write documentation...

(You'll be forgiven for not reading it, as I wrote it yesterday.)

See the 'When using a connection string with the DataContext(string) 
constructor' 
section at: http://code.google.com/p/dblinq2007/wiki/Installation

Specifically, when creating a DataContext with the DataContext(string) 
constructor 
(which should be what the Web406135(string) constructor invokes), you must 
provide 
BOTH the DbLinqProvider AND the DbLinqConnectionType key/value pairs in the 
connection string.  Otherwise, it assumes SqlServer (for DbLinqProvider) and 
"System.Data.SqlClient.SqlConnection, System.Data" (for DbLinqConnectionType).

Obviously, SqlConnection won't be able to connect to a MySQL server... ;-)

Unfortunately, you're not even getting that far; as per the stack trace:

   Could not load file or assembly 'file:///c:\Program Files (x86)\
   Microsoft Visual Studio 9.0\Common7\IDE\DbLinq.MySql.dll' or one of its 
   dependencies. The system cannot find the file specified.

Why is it looking at C:\Program Files (x86)\Microsoft Visual Studio 
9.0\Common7\IDE?

I assure you that DbLinq will ~never be present there (short of insanity), so 
it 
seems rather odd that VS would be looking there.

However, this also appears to point to the problem; as per:

    http://msdn.microsoft.com/en-us/library/1009fa28.aspx

    "The assemblyFile parameter must refer to a URI without escape characters. 
     This method supplies escape characters for all invalid characters in the URI."

then says:

    "assemblyFile is relative to the current directory, and the assembly is loaded
     into the domain of the caller."

What does DbLinq do?

                        // 'vendor' comes from a regex extraction on connectionString
    DataContext.cs:250: assemblyFile = "DbLinq." + vendor + ".dll";
    DataContext.cs:272: assembly = Assembly.LoadFrom(assemblyFile);

The implication here is that, for "normal" apps (e.g. our unit tests, 
console-apps, 
etc.) the Assembly.LoadFrom("DbLinq.MySql.dll") call works because DbLinq.*.dll 
will 
be in the current-working directory.

In this case, however, DbLinq.MySql.dll isn't in the current working directory 
(as VS 
is apparently the app that's being run).

If we want the "normal" directories to be probed (GAC, application base, 
PrivateBinPath, the latter two should be used by ASP.NET apps/etc.) we 
apparently 
need to use Assembly.Load(), NOT Assembly.LoadFrom().

Original comment by jonmpr...@gmail.com on 17 Mar 2010 at 8:01

GoogleCodeExporter commented 9 years ago

Original comment by jonmpr...@gmail.com on 17 Mar 2010 at 9:09

GoogleCodeExporter commented 9 years ago
Hopefully fixed in r1324.  Please test.

Original comment by jonmpr...@gmail.com on 17 Mar 2010 at 9:13

GoogleCodeExporter commented 9 years ago
Aha, so there are an explanation to the madness, isn't there always? 
Actually I did see the wiki installation and I did see the DbLinqConnectionType 
that
I'm missing. My problem is, that I don't know what DbLinqConnectionType to use. 
I'm
using the MySql.Data.dll assembly that you are referencing and I have tried 
dotting
to find out what the Connection type is, but I didn't succeed. Can you bring 
light to
the scene here?

Sorry if I'm too stupid and asks too many questions but Linq is a new world for 
me.
I guess there is nothing more I can do to make it work but to wait for next 
build, or
am I wrong?

Btw. thanks for all the help.

Original comment by Rasmus.C...@gmail.com on 17 Mar 2010 at 9:21

GoogleCodeExporter commented 9 years ago
The value to use for DbLinqConnectionType depends on where you've placed your 
MySql.Data.dll assembly.

If you've placed MySql.Data.dll into the same directory that contains your 
other 
private/non-shared assemblies (such as DbLinq.dll and DbLinq.MySql.dll), then 
it 
doesn't need to be fully qualified:

    DbLinqConnectionType=MySql.Data.MySqlClient.MySqlConnection, MySql.Data

If you've installed MySql.Data.dll into the GAC and wish to use the GAC 
version, then 
you need a fully qualified assembly name, including version, culture, and 
public key 
token, e.g.:

    DbLinqConnectionType=MySql.Data.MySqlClient.MySqlConnection, MySql.Data, 
    Version=5.0.8.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d

(That should be on one line.)

An easy way to obtain the above string is to write an application that consists 
of:

    Console.WriteLine(typeof(MySqlConnection).AssemblyQualifiedName);

Indeed, if/when the MySQL ADO.NET provider changes (including version number 
changes, 
as the current version is now 6.2.2, not the 5.0 version referenced above), 
you'll 
need to update the Assembly Qualified Name value.

Original comment by jonmpr...@gmail.com on 17 Mar 2010 at 10:15

GoogleCodeExporter commented 9 years ago
Ok. I have d/l a new version of MySql.Data.dll from trunk 1325\lib dir, but I'm
unable to find the DbLinq dll. Any clues? Should I d/l every single file in the
src\DbLinq.MySql dir an build the project? I have d/l all these files including
subdirs, but I get a build error as I missing the DbLinq.ProductInfo.cs and
DbLinq.snk from the Properties subdir. They are nowhere to be found in the 
trunk :-(
Where do I find these files?

MySql.Data.dll, DbLinq.dll and DbLinq.MySql.dll are all placed in the Bin dir 
of my
website, so I have justed changed the connection string to the following:

DbLinqProvider=MySql;DbLinqConnectionType=MySql.Data.MySqlClient.MySqlConnection
,
MySql.Data;Server=aaa;Database=bbb;Uid=ccc;Password=ddd;MultipleActiveResultSets
=True;

It still get the same error but of cause when I havn't changed the DbLinq.dll 
and
DqLing.MySql.dll yet

Original comment by Rasmus.C...@gmail.com on 18 Mar 2010 at 7:11

GoogleCodeExporter commented 9 years ago
I d/l the DbLinq.MySql project and in reference I deleted DbLinq.ProductInfo.cs 
ref.
and found the DbLinq.snk and I got the project build successfully. I used the 
newly
created DbLinq.MySql.dll but the result is still the same :-(

I guess it is DbLinq and not DbLinq.MySql that I should rebuild? Is there 
anyway to
d/l the whole project in one piece or must I d/l all files and subdirs.? Mayby 
you
can attach the new DbLinq.dll so I can test?

Original comment by Rasmus.C...@gmail.com on 18 Mar 2010 at 7:26

GoogleCodeExporter commented 9 years ago
Yes, you need to build the DbLinq project not the DbLinq.MySql project.

Are you not using a subversion client?  If you have a subversion client (such 
as `svn`) you can follow the 
instructions at http://code.google.com/p/dblinq2007/source/checkout, e.g.

    svn checkout http://dblinq2007.googlecode.com/svn/trunk/ dblinq2007-read-only

Alternatively, you could install TortoiseSVN from 
http://tortoisesvn.tigris.org/ and checkout a working copy; see:

    http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-checkout.html

You would use the same http://dblinq2007.googlecode.com/svn/trunk/ URL with 
ToroiseSVN as with the command-line `svn` 
client.

Having an svn checkout will allow you to more easily follow along and 
participate in development, confirm bug fixes, 
etc.

Thanks!

Original comment by jonmpr...@gmail.com on 18 Mar 2010 at 1:25

GoogleCodeExporter commented 9 years ago
Hi I tried the above describde but without success :-(

The DbLinq.dll I got build had the size of 392 Kb, but still the same error:

 Could not load file or assembly 'file:///c:\Program Files (x86)\Microsoft Visual
Studio 9.0\Common7\IDE\DbLinq.MySql.dll' or one of its dependencies. The system
cannot find the file specified.
Description: An unhandled exception occurred during the execution of the 
current web
request. Please review the stack trace for more information about the error and 
where
it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or 
assembly
'file:///c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll' or one of its dependencies. The system cannot 
find
the file specified.

Source Error:

Line 34:    #endregion
Line 35: 
Line 36:    public Web406135(string connectionString)
Line 37:        : base(connectionString)
Line 38:    {

Source File: g:\# 
Websites\profile-metaverse.net\App_Code\ProfileMetaverseContext.cs
   Line: 36

Assembly Load Trace: The following information can be helpful to determine why 
the
assembly 'file:///c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll' could not be loaded.

=== Pre-bind state information ===
LOG: User = TECH-T500-RCH\Administrator
LOG: Where-ref bind. Location = c:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\DbLinq.MySql.dll
LOG: Appbase = file:///G:/# Websites/profile-metaverse.net/
LOG: Initial PrivatePath = G:\# Websites\profile-metaverse.net\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will 
only be
probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL file:///c:/Program Files (x86)/Microsoft 
Visual
Studio 9.0/Common7/IDE/DbLinq.MySql.dll.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'file:///c:\Program 
Files
(x86)\Microsoft Visual Studio 9.0\Common7\IDE\DbLinq.MySql.dll' or one of its
dependencies. The system cannot find the file specified.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence
assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean
throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence
assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean
throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence
securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean
forIntrospection, StackCrawlMark& stackMark) +83
   System.Reflection.Assembly.LoadFrom(String assemblyFile) +32
   DbLinq.Data.Linq.DataContext.GetVendorInfo(String& connectionString, Assembly&
assembly, String& typeName) +238

[ArgumentException: Unable to load the `DbLinq.MySql.dll' DbLinq vendor within
assembly `MySql'.
Parameter name: connectionString]
   DbLinq.Data.Linq.DataContext.GetVendorInfo(String& connectionString, Assembly&
assembly, String& typeName) +329
   DbLinq.Data.Linq.DataContext.GetVendor(String& connectionString) +54
   DbLinq.Data.Linq.DataContext..ctor(String connectionString) +128
   Web406135..ctor(String connectionString) in g:\#
Websites\profile-metaverse.net\App_Code\ProfileMetaverseContext.cs:36
   UserProfile.UserCount() in g:\#
Websites\profile-metaverse.net\App_Code\UserProfile.cs:41
   Page_test.Page_Load(Object sender, EventArgs e) in g:\#
Websites\profile-metaverse.net\Test\RCH\test.aspx.cs:39
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t,
EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs
e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +627

Do I need some kind of settings in Web.config so DbLinq knows where to find the 
dll?
Am I the only that wants to use this on a website?

Original comment by Rasmus.C...@gmail.com on 19 Mar 2010 at 10:06

GoogleCodeExporter commented 9 years ago
I don't know why, but you don't have the right DbLinq.dll.

My build/DbLinq.dll is 400896 bytes (~400k), which is larger than yours (and 
this 
isn't the debug assembly).  Furthermore, your stack trace still has 
Assembly.LoadFrom(), which r1324 removed.

Because I'm nice, I'll provide my copy of DbLinq.dll:

    http://www.jprl.com/tmp/DbLinq.dll

However, I don't want to make a habit of providing pre-release assemblies for 
testing.

Original comment by jonmpr...@gmail.com on 19 Mar 2010 at 1:26

GoogleCodeExporter commented 9 years ago
Thanks, I found out of it. In my attempts to get a working solution I had 
installed
the old dll in the GAC and therefore the website was using these. After I 
deleted
these I don't get the above error, so that is corrected now. I did however get 
an
error about my connectionstring, that 'MultipleActiveResultSets=True' is not a 
valid
keyword, but I guess that is's only MSSQL that supports this keyword.

Btw. thanks for the DbLinq.dll. It is the exact same that I got build. You can 
see
that the size matches: 400896 bytes / 1024 = 391,5 kB

Later tonight I'll be testing if everything works, I expect that :-)

Original comment by Rasmus.C...@gmail.com on 19 Mar 2010 at 1:51