Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can reflection ever fail in C#?

Tags:

c#

reflection

We have an application which we are developing in C#. We store all resources in a central resource DLL, the resource contains images, icons and strings from which we support multiple cultures.

We access the resources from any project in the solution using the following code;

private ResourceManager ResMan;
ResMan = new ResourceManager("libResx.Resource", Assembly.ReflectionOnlyLoad("libResx"));

Then we access any element of the resource using;

btnClose.Text = ResMan.GetString("btnClose");

Apart from the Resource DLL being missing, is there anything that could cause reflection to fail to find the resource DLL (assembly). So far in testing it has been flawless, is there anything we should be aware of when this is eventually deployed into the wild?

Can reflection fail?


1 Answers

It can fail. You can attribute an assembly to prevent reflection from another assembly outside of the same namespace.

like image 132
Steven Behnke Avatar answered May 23 '26 00:05

Steven Behnke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!