加载资源程序集但不“锁定”文件

发布于 2024-12-21 11:18:48 字数 729 浏览 5 评论 0原文

我在加载包含资源 xaml 的程序集时遇到问题。 问题是我不允许“锁定”该文件,因为更新可能会在以后替换它。

首先我像这样加载它:

Uri uriProperties;
ResourceDictionary xResources;
uriProperties = new Uri("/xResources;component/xResources.xaml", UriKind.Relative);
xResources = Application.LoadComponent(uriProperties) as ResourceDictionary;

效果很好。文件未锁定。

现在我遇到了另一个问题,我必须将其放入另一个程序集中。使用相对 Uri 加载它不再起作用,我现在有了完整路径。

我尝试过:

Assembly.LoadFrom(xPath + @"/xResources.dll");
xResources = new ResourceDictionary();
xResources.Source = new Uri(@"pack://application:,,,/xResources;component/xResources.xaml"); 

也适用于应用程序。但它会锁定文件。

如何加载程序集并使用完整路径获取资源字典但不锁定文件?

如果有一个不使用卷影复制或更改内容路径等的解决方案,那就太好了......

I got a problem loading my assembly containing a resource xaml.
The problem is I am not allowed to "lock" the file, because an update may replace it later.

First I loaded it like this:

Uri uriProperties;
ResourceDictionary xResources;
uriProperties = new Uri("/xResources;component/xResources.xaml", UriKind.Relative);
xResources = Application.LoadComponent(uriProperties) as ResourceDictionary;

That worked fine. File is not locked.

Now I got another problem I had to put it into an other assembly. Loading it with the relative Uri does not work anymore, I have a full path now.

I tried:

Assembly.LoadFrom(xPath + @"/xResources.dll");
xResources = new ResourceDictionary();
xResources.Source = new Uri(@"pack://application:,,,/xResources;component/xResources.xaml"); 

also works in the application. But it locks the file.

How do I load the assembly and get my resourcedictionary with using a full path but without locking the file?

Would be nice if there was a solution without using shadow copying or changing content paths etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2024-12-28 11:18:48

不确定这是否能解决您的问题,但值得一试:

var bytes = File.ReadAllBytes("assemblypath");
var assembly = Assembly.Load(bytes);

Not sure if this will solve your problem, but it's worth the shot:

var bytes = File.ReadAllBytes("assemblypath");
var assembly = Assembly.Load(bytes);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文