How can I reference Properties?

Jan 21, 2014 at 1:34 AM
I sometimes copy code from .NET Bio to adapt to use as a template to adapt to my own purposes.

When I do this, I often find expressions like:

throw new ArgumentException(Properties.Resource.DestArrayNotLargeEnough);

They always cause compilation errors and I have not figured out how to fix them.

Am I missing a using or a reference?

Thanks,

Mark
Developer
Jan 21, 2014 at 1:41 AM
Hi Mark,

The problem is that the bit:

Properties.Resource.DestArrayNotLargeEnough

is referring to a string that is stored elsewhere in the project you copied from (it is a stored string for the error message), and so the reference is not found, leading to compilation errors.

Easiest way to avoid this is probably just to rename it as a string variable right there:
throw new ArgumentException("DestArrayNotLargeEnough"); 
Or copy over the projects resource file as well so it matches.

Hope that helps,
Nigel
Marked as answer by RMarkT on 1/20/2014 at 6:48 PM
Jan 21, 2014 at 2:54 AM
Nigel:

That solved it.

In case someone else has the same issue, what I did was:

1) Add Resource.resx and Resource.Designer.cs from .Net Bio into my project.

2) Change "namespace Bio.Properties" to "namespace MyProject.Properties" in Resource.Designer.cs.

Thanks,

Mark