Assembly not found

V

V. Jenks

I'm using reflection to dynamically load an assembly and
even though I'm sure the assembly is present, I keep
getting an error telling me the "assembly or one of its
references can't be found".

I do in fact have a reference to the assembly in question
in the project and I even tried declaring it with "using"
at the top of the class file.

Here's the method that fails:

public IDataAdapter CreateAdapter(string query,
IDbConnection connection)
{
object[] args = {query, connection};

//load the assembly and class
Assembly asmb = Assembly.Load("FirebirdSql.Data.Firebird");

Type type = asmb.GetType("FbDataAdapter");

IDataAdapter da = Activator.CreateInstance(type, args)
as IDataAdapter;

return da;
}

The "FirebirdSql.Data.Firebird" assembly can't be found,
even though it's there. It's in my GAC and available as
I'm using it elsewhere w/o a problem.

What could be the problem?

Thanks!

-v
 
F

Frans Bouma [C# MVP]

V. Jenks said:
I'm using reflection to dynamically load an assembly and
even though I'm sure the assembly is present, I keep
getting an error telling me the "assembly or one of its
references can't be found".

I do in fact have a reference to the assembly in question
in the project and I even tried declaring it with "using"
at the top of the class file.

Here's the method that fails:

public IDataAdapter CreateAdapter(string query,
IDbConnection connection)
{
object[] args = {query, connection};

//load the assembly and class
Assembly asmb = Assembly.Load("FirebirdSql.Data.Firebird");

Type type = asmb.GetType("FbDataAdapter");

IDataAdapter da = Activator.CreateInstance(type, args)
as IDataAdapter;

return da;
}

The "FirebirdSql.Data.Firebird" assembly can't be found,
even though it's there. It's in my GAC and available as
I'm using it elsewhere w/o a problem.

Start the tool fuslogvw.exe and examine the log fusion has written when
it failed to load the assembly. As the firebird provider is signed,
perhaps you should specify it's full name. Either way, the log will
explain what paths it has checked and for which file.

Fuslogvw.exe is part of the .net sdk and if you have vs.net installed
on your system you have it installed as well.

Frans.
 
G

Guest

I tried this, there is nothing listed in the log at all.
Also, if I choose anything but "Default" from the radio
button list on the right, I get an error that says:

"Error: Unable to open cache file!"

I am using the full name of the Firebird driver. If I
switch to SQL Server, it also fails.

But...in the very same class, this method runs and works
just fine, which seems very strange to me:

public IDataHelper Create()
{
//get configuration values for the assembly and class
string assemblyName = Config.DataHelperFactoryAssembly;
string className = Config.DataHelperFactoryClass;

//load the assembly and class
IDataHelper dh =
(IDataHelper)Assembly.Load(assemblyName).CreateInstance(className);

return dh;
}

Config.DataHelperFactoryAssembly and
Config.DataHelperFactoryClass call an assembly & class I
that I wrote myself.....and it works.

What's the problem with calling external assemblies?

I would use LoadFrom but I need it to be more flexible than
that...I can't very well make it portable if I have to
worry about paths breaking to my assemblies.

Thanks!
-----Original Message-----
V. Jenks said:
I'm using reflection to dynamically load an assembly and
even though I'm sure the assembly is present, I keep
getting an error telling me the "assembly or one of its
references can't be found".

I do in fact have a reference to the assembly in question
in the project and I even tried declaring it with "using"
at the top of the class file.

Here's the method that fails:

public IDataAdapter CreateAdapter(string query,
IDbConnection connection)
{
object[] args = {query, connection};

//load the assembly and class
Assembly asmb = Assembly.Load("FirebirdSql.Data.Firebird");

Type type = asmb.GetType("FbDataAdapter");

IDataAdapter da = Activator.CreateInstance(type, args)
as IDataAdapter;

return da;
}

The "FirebirdSql.Data.Firebird" assembly can't be found,
even though it's there. It's in my GAC and available as
I'm using it elsewhere w/o a problem.

Start the tool fuslogvw.exe and examine the log fusion has written when
it failed to load the assembly. As the firebird provider is signed,
perhaps you should specify it's full name. Either way, the log will
explain what paths it has checked and for which file.

Fuslogvw.exe is part of the .net sdk and if you have vs.net installed
on your system you have it installed as well.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog : http://weblogs.asp.net/FBouma
Microsoft MVP (C#)
.
 
D

David Levine

You have not described where the assemblies are located in relation to the
executable. Is the assembly in the GAC, in a local directory, etc? Does the
other assembly have dependencies to other assemblies?

Also, using the form Assembly.Load usually requires that you specify the
assembly's full 4 part name (name, version, culture, public key token).

There's nothing intrinsically inflexible about using LoadFrom with paths,
but there are side effects.

I tried this, there is nothing listed in the log at all.
Also, if I choose anything but "Default" from the radio
button list on the right, I get an error that says:

"Error: Unable to open cache file!"

I am using the full name of the Firebird driver. If I
switch to SQL Server, it also fails.

But...in the very same class, this method runs and works
just fine, which seems very strange to me:

public IDataHelper Create()
{
//get configuration values for the assembly and class
string assemblyName = Config.DataHelperFactoryAssembly;
string className = Config.DataHelperFactoryClass;

//load the assembly and class
IDataHelper dh =
(IDataHelper)Assembly.Load(assemblyName).CreateInstance(className);

return dh;
}

Config.DataHelperFactoryAssembly and
Config.DataHelperFactoryClass call an assembly & class I
that I wrote myself.....and it works.

What's the problem with calling external assemblies?

I would use LoadFrom but I need it to be more flexible than
that...I can't very well make it portable if I have to
worry about paths breaking to my assemblies.

Thanks!
-----Original Message-----
V. Jenks said:
I'm using reflection to dynamically load an assembly and
even though I'm sure the assembly is present, I keep
getting an error telling me the "assembly or one of its
references can't be found".

I do in fact have a reference to the assembly in question
in the project and I even tried declaring it with "using"
at the top of the class file.

Here's the method that fails:

public IDataAdapter CreateAdapter(string query,
IDbConnection connection)
{
object[] args = {query, connection};

//load the assembly and class
Assembly asmb = Assembly.Load("FirebirdSql.Data.Firebird");

Type type = asmb.GetType("FbDataAdapter");

IDataAdapter da = Activator.CreateInstance(type, args)
as IDataAdapter;

return da;
}

The "FirebirdSql.Data.Firebird" assembly can't be found,
even though it's there. It's in my GAC and available as
I'm using it elsewhere w/o a problem.

Start the tool fuslogvw.exe and examine the log fusion has written when
it failed to load the assembly. As the firebird provider is signed,
perhaps you should specify it's full name. Either way, the log will
explain what paths it has checked and for which file.

Fuslogvw.exe is part of the .net sdk and if you have vs.net installed
on your system you have it installed as well.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog : http://weblogs.asp.net/FBouma
Microsoft MVP (C#)
.
 
R

Richard Blewett [DevelopMentor]

If the FirebirdSql.Data.Firebird assembly is located somewhere other than the application directory or a directory under the app directory called FirebirdSql.Data.Firebird then it will not be found by default. If it is in the GAC of at a codebase hint you will have to fully qualofy the assembly name with the version, culture and public key token. If its in some other directory under the app directory you will have to add a <probing> element into your app config file to extend the paths searched under the app directory.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I'm using reflection to dynamically load an assembly and
even though I'm sure the assembly is present, I keep
getting an error telling me the "assembly or one of its
references can't be found".

I do in fact have a reference to the assembly in question
in the project and I even tried declaring it with "using"
at the top of the class file.

Here's the method that fails:

public IDataAdapter CreateAdapter(string query,
IDbConnection connection)
{
object[] args = {query, connection};

//load the assembly and class
Assembly asmb = Assembly.Load("FirebirdSql.Data.Firebird");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top