Pregunta

I am trying to compile a piece of Code at Runtime with the VBCodeProvider class. It works great with one exception. I can't access any members of the System.Drawing Namespace. I do an "Imports System.Drawing" at the beginning of the code which does compile without an error (so I guess the reference is there alright) but when I try to define for example a graphics object with "Dim g as Graphics" or "Dim g as System.Drawing.Graphics" I get an exception on compilation: {[...] error BC30002: Der Typ "Graphics" ist nicht definiert. (The type Graphics is not defined)}

When I try to add the System.Drawing.dll to the ReferencedAssemblies of the CompilerOptions then I get a whole bunch of other compilation errors so I guess that's not the solution. I don't really get why this problem is there. For example in the same code I use members of System.Math which work.

Does anyone have an idea or tip for me of what I may be doing wrong?

Thank you in advance. Jens

edit due to lack of reputation:

Thank you for your help. Typical thing: You try and search for over an hour, then you ask here and 10 minutes later you find the solution yourself:

The problem was with how I referenced the system.drawing.dll in the compileroptions. I did use an absolute path "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Drawing.dll" and that gave me 19 exceptions in some code I did not even write myself.!

enter image description here

What worked was to use a relative path. e.g.

PM.ReferencedAssemblies.Add("System.Drawing.dll")

I don't know what the real difference is, but at least this works. :-)

Thank you very much for your help!

¿Fue útil?

Solución

Typical thing: You try and search for over an hour, then you ask here and 10 minutes later you find the solution yourself:

The problem was with how I referenced the system.drawing.dll in the compileroptions. I did use an absolute path C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Drawing.dll and that gave me 19 exceptions in some code I did not even write myself.

See in image here

What worked was to use a relative path. e.g.

PM.ReferencedAssemblies.Add("System.Drawing.dll")

I don't know what the real difference is, but at least this works.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top