user627085
user627085

Reputation: 11

Create Dll dynamic from c#

Hey, I use the CSharpCodeProvider class to compile c# code into a dll.

That works fine, but only with sourcecode. I would compile into my dll Resources.

I have found the class

CodeCompileUnit codeCompileUnit =
    StronglyTypedResourceBuilder.Create(
       dicResources, "Resources", 
       "Customer.Premium.XmlAppResources.Properties", cSharpCodeProvider,
       true, out errors
    );

this class creates my a perfect c# class that i can compile and i get a wonderfull dll =) BUT :P ...

if i use this dll and i work with the CultureInfo.CurrentCulture i get an error like this :

For the specified culture or the neutral culture resources could not be found. Make sure that Customer.Premium.XmlAppResources.Properties.Resources.resources embedded at compile correctly in the assembly Customer.Premium.XmlAppResources was, or that the required satellite assemblies can be loaded and completely unsigned.

I have no Customer.Premium.XmlAppResources.Properties.Resources.resources in my dll.. and i have no idee where i get this from ...

Upvotes: 1

Views: 1549

Answers (4)

user627085
user627085

Reputation: 11

Yes Thanks! This is exactly what I need:

  IResourceWriter writer = new ResourceWriter("myResources.resources");

  // Adds resources to the resource writer.
  writer.AddResource("String 1", "First String");

  writer.AddResource("String 2", "Second String");

  writer.AddResource("String 3", "Third String");

  // Writes the resources to the file or stream, and closes it.
  writer.Close();

Upvotes: 0

Alois Kraus
Alois Kraus

Reputation: 13545

The issue you have is that the StronglyTypedResourceBuilder creates from your resources a C# class which has a property ResourceManager where this one has the wrong namespace or you generate a ResourceManager by hand and assume a different resource name. From where did you get the ResourceManager that did cause the problem? You can work around this by using an overload of the ResourceBuilder where you can specify the Resource Base Name, Resource Name and the namespace of the generated class. The naming scheme is

  • Resource Base Name: Customer.Premium.XmlAppResources.Properties
  • Resource Name: Resources
  • Resource Extension: .ressources

This 3 things define the resource name which is stored as resource stream in your assembly. In this case Customer.Premium.XmlAppResources.Properties.Resources.ressources

Please check with e.g. Reflector if under which name the resources are created in your assembly and alter your namespace accordingly to make either the creator of the ResourceManager happy or change the creation of the ResourceManager to successfully load the resources.

Yours, Alois Kraus

Upvotes: 0

Tedd Hansen
Tedd Hansen

Reputation: 12316

If I understand your question correctly: You can do this from the command line using resgen.exe. It will generate a resource file you can use from .Net applications.

Upvotes: 1

Joel Coehoorn
Joel Coehoorn

Reputation: 416121

You're making this way harder than it needs to be. Just choose a Class Library Project type when creating your project and the output will be a dll, resources and all.

Upvotes: 0

Related Questions