通过加载一个字节装配失去位置 [英] Loading an assembly by Bytes loses the location

查看:111
本文介绍了通过加载一个字节装配失去位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下

VAR loadedAssembly =的Assembly.Load(File.ContentsAsBytes)加载程序集;

File.ContentAsBytes返回DLL作为字节[] ,通过以下

the File.ContentAsBytes returns the dll as a byte[], via the following

System.IO.File.ReadAllBytes(DLL的位置);

问题是加载的程序集( loadedAssembly )失去其phyisical位置

The issue is the loaded assembly (loadedAssembly) loses its phyisical location


  • loadedAssembly.CodeBase - 设置为它加载它(这是不正确)

  • loadedAssembly.Location大会 - 为空

有没有办法从字节[] 并得到了类似的结果,为 Assembly.LoadFile <加载/ code>,因为我需要的结果与 AppDomain.CurrentDomain.AssemblyResolve

Is there a way to load from a byte[] and getting a similar result to Assembly.LoadFile as I need the the result to work with the AppDomain.CurrentDomain.AssemblyResolve

推荐答案

一个字节数组字节[] 简直就是在内存中的字节流。它在所有的任何文件没有相关性。该字节数组可能已经从文件中读取,从网络服务器下载的,或由一个随机数发生器自发形成的。没有多余的数据,与它去。

A byte array byte[] is simply a stream of bytes in memory. It has no correlation to any file at all. That byte array could have been read from file, downloaded from a web server, or created spontaneously by a random number generator. There is no extra data that "goes with it".

如果你想保持那里的字节数组最初是从读取的文件位置,则必须维护数据在单独另一个变量。有没有办法附加附加数据到字节[] 变量。

If you want to maintain the file location where the byte array was originally read from, then you must maintain that data separately in another variable. There is no way to "attach" the extra data to the byte[] variable.

当您使用的Assembly.Load 加载字节数组作为一个组件,它没有办法知道那个字节数组是从哪里来的,因为额外的数据没有提供给加载功能。

When you use Assembly.Load to load the byte array as an assembly, it has no way to know where that byte array came from, because that extra data is not provided to the Load function.

作为一种解决方法,有没有一种方式,您可以将您的字节数组保存到一个临时文件,使用 Assembly.LoadFile 来给你你需要的数据和链接位置回你原来的字节数组?

As a workaround, is there a way you can save your byte array to a temporary file, use Assembly.LoadFile to give you the data you need and link the Location back to your original byte array?

这篇关于通过加载一个字节装配失去位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆