现有一程序
我做了两个类库ClassLibrary1,ClassLibrary2
其中ClassLibrary2引用ClassLibrary1,并使用ClassLibrary1中的方法。。然后我建立一程序,将ClassLibrary2添加到程序中
程序没有添加对ClassLibrary1的引用
Dim b() As Byte = resource.GetObject("ClassLibrary2")
ass = System.Reflection.Assembly.Load(b)
Dim mytype As Type = ass.GetType("ClassLibrary2.Class1")
Dim Method As MethodInfo = mytype.GetMethod("Method2")
Dim obj As Object = ass.CreateInstance("ClassLibrary2.Class1")
Dim result As String = Method.Invoke(obj, Nothing).ToString()//这句出现异常(因为method方法需要调用类库1中的方法)程序执行错误我如果将类库1的引用添加进来,则程序可以运行很明显 程序异常是因为没有添加对类库1的引用我现在就是向问一下,在添加类库2的时候,能不能自己包涵对类库1的引用。。望高手进来解答一下,我在线等
我做了两个类库ClassLibrary1,ClassLibrary2
其中ClassLibrary2引用ClassLibrary1,并使用ClassLibrary1中的方法。。然后我建立一程序,将ClassLibrary2添加到程序中
程序没有添加对ClassLibrary1的引用
Dim b() As Byte = resource.GetObject("ClassLibrary2")
ass = System.Reflection.Assembly.Load(b)
Dim mytype As Type = ass.GetType("ClassLibrary2.Class1")
Dim Method As MethodInfo = mytype.GetMethod("Method2")
Dim obj As Object = ass.CreateInstance("ClassLibrary2.Class1")
Dim result As String = Method.Invoke(obj, Nothing).ToString()//这句出现异常(因为method方法需要调用类库1中的方法)程序执行错误我如果将类库1的引用添加进来,则程序可以运行很明显 程序异常是因为没有添加对类库1的引用我现在就是向问一下,在添加类库2的时候,能不能自己包涵对类库1的引用。。望高手进来解答一下,我在线等
by the target of an invocation. ---> System.IO.FileNotFoundException:
Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.
File name: 'ClassLibrary1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
at ClassLibrary2.Class1..ctor()这是更多提示。。
谁能给说一下呢
程序是这样的
我是将这两个类库存放到WEB SERVICES中
然后,我将类库2通过资源管理器,返回一个BYTE数组 web services中的方法是
Dim ass As Assembly = Assembly.GetExecutingAssembly
Dim resource As Resources.ResourceManager = New Resources.ResourceManager("WebService2.Resources", ass)
Dim b() As Byte = resource.GetObject("ClassLibrary2")
Return b然后程序中通过反射调用这个byte数组的内容方法。。
ass = System.Reflection.Assembly.Load(b) /b就是返回的那个byte数组
Dim mytype As Type = ass.GetType("ClassLibrary2.Class1")
Dim Method As MethodInfo = mytype.GetMethod("Method2")
Dim obj As Object = ass.CreateInstance("ClassLibrary2.Class1")
Dim result As String = Method.Invoke(obj, Nothing).ToString()//这句出现异常(因为method方法需要调用类库1中的方法) 整个程序是这样的如果您有时间的话,请指教一下,谢谢。。
那ClassLibrary1呢?
我刚才试了试程序,如果将ClassLibrary1添加到项目中,则程序会自动再当前程序中查找ClassLibrary1,程序运行不会有问题如果没有Classlibrary1
Catch ex As TargetInvocationException
Throw ex.InnerException
End Try
错误信息
File notfound exception
Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.我想在就是想问一下 vs中有没有自动处理的机制,将ClassLibrary2中涉及的类库,自动给包涵到里边()。。
我感觉是不可能的,如果这样的话,我如果classlibrary2调用很多其他类库,那classlibrary2则会很大解决方法是不是就是将classlibray2中调用的类库,要事先加入到程序中。。还是有其他的解决方法呢
那意思是 我必须吧这个classlibrary1存放到当前程序中,他的自动处理机制就是再当前程序中查找
我吧classlibrary1放到当前程序中可以使用,原来还可以用呢,刚才又不可以用了那我需要将这个类库存放到什么位置呢。。 它找得着的位置是什么地方
谢谢。。
<runtime>
<gcConcurrent enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<publisherPolicy apply="yes" />
<probing privatePath="这个是你的相对路径(exe的)" />
</assemblyBinding>
</runtime>
谢谢你了
lake_cx
结贴了。。
看看怎么把分送你,呵呵,我刚进来的