Could not load file or assembly

T

Terry Holland

I am using the following code to execute a method of a class in an assembly

Public Shared Function NewPerson() As TZ_Interfaces.IPerson
'This factory will return an instance of clsPerson with ID=intID
'from the BLL assembly defined in BLLCustomAssembly setting

Dim strType As String = BLLCustomAssembly '
My.Settings.BLLCustomAssembly

Dim objPerson As TZ_Interfaces.IPerson = Nothing
Dim objAssembly As Assembly = Nothing
Dim objType As Type = Nothing

objAssembly = Assembly.LoadFrom(strType & ".dll")
objType = objAssembly.GetType(strType & ".BLL.clsPerson")

'Invoke the NewPerson shared method of clsPerson
Dim objMethodInfo As MethodInfo = objType.GetMethod("NewPerson",
System.Reflection.BindingFlags.[Static] Or BindingFlags.[Public])
objPerson = objMethodInfo.Invoke(objType, Nothing)


Return objPerson
End Function

If my calling code is a WinForms app, this code works as long as the DLL is
in the bin\debug directory of the WinForms assembly.

When I try the same thing with my calling code being an ASP.Net app I get
the following error, even if the relevant dll is in the bin directory of the
web app

Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual
Studio 8\Common7\IDE\~\Bin......


Advice appreciated
 
G

Guest

I am using the following code to execute a method of a class in an assembly

Public Shared Function NewPerson() As TZ_Interfaces.IPerson
            'This factory will return an instance of clsPerson with ID=intID
            'from the BLL assembly defined in BLLCustomAssembly setting

            Dim strType As String = BLLCustomAssembly '
My.Settings.BLLCustomAssembly

            Dim objPerson As TZ_Interfaces.IPerson = Nothing
            Dim objAssembly As Assembly = Nothing
            Dim objType As Type = Nothing

            objAssembly = Assembly.LoadFrom(strType & ".dll")
            objType = objAssembly.GetType(strType & ".BLL.clsPerson")

            'Invoke the NewPerson shared method of clsPerson
            Dim objMethodInfo As MethodInfo = objType.GetMethod("NewPerson",
System.Reflection.BindingFlags.[Static] Or BindingFlags.[Public])
            objPerson = objMethodInfo.Invoke(objType, Nothing)

            Return objPerson
        End Function

If my calling code is a WinForms app, this code works as long as the DLL is
in the bin\debug directory of the WinForms assembly.

When I try the same thing with my calling code being an ASP.Net app I get
the following error, even if the relevant dll is in the bin directory of the
web app

Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual
Studio 8\Common7\IDE\~\Bin......

Advice appreciated

It seems to me that this DLL was dependent on another DLL which was
not present in the bin directory. It goes to C:\Program Files
\Microsoft Visual Studio 8\.... where ASP.NET account has no access
rights. When you run your code in a WinForms app you run it under your
own user account and this works.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top