Search Results

Search found 89 results on 4 pages for 'codedom'.

Page 1/4 | 1 2 3 4  | Next Page >

  • C# CodeDom - making project's forms accessible for scripts.

    - by michal
    Hi, I'm learning CodeDom scripting, I started with http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx Now I'd like to allow script modify the project's form (for learning purposes only). I suppose I need to create new field for a class I'm generating which refers "this". However I have no idea how can I set a reference for script-accessible object ... ? Or can I directly publish some class member (like "this" or "button1") to a CodeDom script structure?

    Read the article

  • T4 vs CodeDom vs Oslo

    - by Ryan Riley
    In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo, T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven design from user stories. The first step will be to create the tests from the user stories, but we want the domain experts to be able to write their stories in a variety of different media (e.g. custom app, Word, etc.) and still generate the tests from the stories. What I know so far: CodeDom requires .NET but can only output .NET class files (e.g. .cs, .vb). Level of difficulty is fairly high. T4 requires CodeDom and VS Standard+. Level of difficulty is fairly reasonable, especially with the T4 Toolbox. Oslo is very new. I have no idea of the dependencies, but I imagine you must be on at least .NET 3.5. I'm also not certain as to the code generation abilities or the complexity for adding new grammars. However, domain experts could probably write user stories in Intellipad quite easily. Also not sure about ease of converting stories in Word to an MGrammar. What are your thoughts, experiences, etc. with any of the above tools. We want to stick with Microsoft or open source tools.

    Read the article

  • FSharp.Compiler.CodeDom for VS2008 and VS2010 side-by-side

    - by SztupY
    I'm using FSharp.Compiler.CodeDom to dynamically create F# classes. The problem is, that I have both VS2008 and VS2010 on my computer side-by-side (they works fine), and using F# in this configuration is buggy at best: If I don't install InstallFSharp.msi, then under VS2008 the built classes complain about not finding FSharp.Core (even if they're referenced) If I install InstallFSharp.msi, then under VS2008 the built classes will use the F# built for VS2010, and will throw a binary-incompatibility exception, because it will load the .net4 variant: FSC: error FS0219: The referenced or default base CLI library 'mscorlib' is binary- incompatible with the referenced F# core library 'C:\Program Files (x86)\Microsoft F#\v4.0\FSharp.Core.dll'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using. If I replace the F# found at the previous location to the separately installed dll-s, then of course VS2010 will complain about binary-incompatibility Am I overlooking something, or they won't simply work for a shared environment like this? This might mean real problems when I deploy the applications. Thanks

    Read the article

  • creating enumeration using .NET's CodeDom

    - by Manish Sinha
    Hi, I want to create an Enumeration using CodeDom API. I have searched enough on the internet and I get results which are hardly of any use. What I want to generate is public enum bug_tracker_type { [Description("Bugzilla")] Bugzilla, [Description("Debbugs")] Debbugs, [Description("PHP Project Bugtracker")] PHP_Project_Bugtracker, [Description("Google Code")] Google_Code } I used CodeTypeDeclaration and set it's IsEnum property as true, created a name, and set it's Attributes. Now the biggest problem is how to populate the body? I tried CodeTypeMember mem = new CodeTypeMember(); mem.Name = WadlSharpUtils.CreateIdentifier(discreteValue.value); mem.CustomAttributes.Add(new CodeAttributeDeclaration(discreteValue.value)); // enumCandidate is an instance of CodeTypeDeclaration enumCandidate.Members.Add(mem); Though using this solution I can generate the Description attributes, the end of line would be ; and not ,

    Read the article

  • CodeDom : compile partial class

    - by James
    I'm attempting to compile code in a text file to change a value in a TextBox on the main form of a WinForms application. Ie. add another partial class with method to the calling form. The form has one button (button1) and one TextBox (textBox1). The code in the text file is: this.textBox1.Text = "Hello World!!"; And the code: namespace WinFormCodeCompile { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Load code from file StreamReader sReader = new StreamReader(@"Code.txt"); string input = sReader.ReadToEnd(); sReader.Close(); // Code literal string code = @"using System; using System.Windows.Forms; namespace WinFormCodeCompile { public partial class Form1 : Form { public void UpdateText() {" + input + @" } } }"; // Compile code CSharpCodeProvider cProv = new CSharpCodeProvider(); CompilerParameters cParams = new CompilerParameters(); cParams.ReferencedAssemblies.Add("mscorlib.dll"); cParams.ReferencedAssemblies.Add("System.dll"); cParams.ReferencedAssemblies.Add("System.Windows.Forms.dll"); cParams.GenerateExecutable = false; cParams.GenerateInMemory = true; CompilerResults cResults = cProv.CompileAssemblyFromSource(cParams, code); // Check for errors if (cResults.Errors.Count != 0) { foreach (var er in cResults.Errors) { MessageBox.Show(er.ToString()); } } else { // Attempt to execute method. object obj = cResults.CompiledAssembly.CreateInstance("WinFormCodeCompile.Form1"); Type t = obj.GetType(); t.InvokeMember("UpdateText", BindingFlags.InvokeMethod, null, obj, null); } } } } When I compile the code, the CompilerResults returns an error that says WinFormCodeCompile.Form1 does not contain a definition for textBox1. Is there a way to dynamically create another partial class file to the calling assembly and execute that code? I assume I'm missing something really simple here.

    Read the article

  • CodeDOM: Adding DebuggerStepThroughAttribute to property

    - by Dont Ask
    I know how to add a DebuggerStepThroughAttribute to a method or a constructor, usually you add it to the CustomAttributes collection of a code member. But I don't see a way to do this for the setter and getter of a C# property, because neither of them provides this collection where you add the attributes. Does anyone have a clue?

    Read the article

  • Hiding Command Prompt with CodeDomProvider

    - by j-t-s
    Hi All I've just got my own little custom c# compiler made, using the article from MSDN. But, when I create a new Windows Forms application using my sample compiler, the MSDOS window also appears, and if I close the DOS window, my WinForms app closes too. How can I tell the Compiler? not to show the MSDOS window at all? Thank you :) Here's my code: using System; namespace JTS { public class CSCompiler { protected string ot, rt, ss, es; protected bool rg, cg; public string Compile(String se, String fe, String[] rdas, String[] fs, Boolean rn) { System.CodeDom.Compiler.CodeDomProvider CODEPROV = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp"); ot = fe; System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters(); // Ensure the compiler generates an EXE file, not a DLL. PARAMS.GenerateExecutable = true; PARAMS.OutputAssembly = ot; PARAMS.CompilerOptions = "/target:winexe"; PARAMS.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location); PARAMS.LinkedResources.Add("this.ico"); foreach (String ay in rdas) { if (ay.Contains(".dll")) PARAMS.ReferencedAssemblies.Add(ay); else { string refd = ay; refd = refd + ".dll"; PARAMS.ReferencedAssemblies.Add(refd); } } System.CodeDom.Compiler.CompilerResults rs = CODEPROV.CompileAssemblyFromFile(PARAMS, fs); if (rs.Errors.Count > 0) { foreach (System.CodeDom.Compiler.CompilerError COMERR in rs.Errors) { es = es + "Line number: " + COMERR.Line + ", Error number: " + COMERR.ErrorNumber + ", '" + COMERR.ErrorText + ";" + Environment.NewLine + Environment.NewLine; } } else { // Compilation succeeded. es = "Compilation Succeeded."; if (rn) System.Diagnostics.Process.Start(ot); } return es; } } }

    Read the article

  • Hiding Command Prompt with CodeDomProvider

    - by j-t-s
    Hi All I've just got my own little custom c# compiler made, using the article from MSDN. But, when I create a new Windows Forms application using my sample compiler, the MSDOS window also appears, and if I close the DOS window, my WinForms app closes too. How can I tell the Compiler? not to show the MSDOS window at all? Thank you :) Here's my code: using System; namespace JTS { public class CSCompiler { protected string ot, rt, ss, es; protected bool rg, cg; public string Compile(String se, String fe, String[] rdas, String[] fs, Boolean rn) { System.CodeDom.Compiler.CodeDomProvider CODEPROV = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp"); ot = fe; System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters(); // Ensure the compiler generates an EXE file, not a DLL. PARAMS.GenerateExecutable = true; PARAMS.OutputAssembly = ot; PARAMS.CompilerOptions = "/target:winexe"; PARAMS.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location); PARAMS.LinkedResources.Add("this.ico"); foreach (String ay in rdas) { if (ay.Contains(".dll")) PARAMS.ReferencedAssemblies.Add(ay); else { string refd = ay; refd = refd + ".dll"; PARAMS.ReferencedAssemblies.Add(refd); } } System.CodeDom.Compiler.CompilerResults rs = CODEPROV.CompileAssemblyFromFile(PARAMS, fs); if (rs.Errors.Count > 0) { foreach (System.CodeDom.Compiler.CompilerError COMERR in rs.Errors) { es = es + "Line number: " + COMERR.Line + ", Error number: " + COMERR.ErrorNumber + ", '" + COMERR.ErrorText + ";" + Environment.NewLine + Environment.NewLine; } } else { // Compilation succeeded. es = "Compilation Succeeded."; if (rn) System.Diagnostics.Process.Start(ot); } return es; } } }

    Read the article

  • WinForm Design View Error

    - by Ramiz Uddin
    I'm getting the following error on form design: Hide Call Stack at EnvDTE80.CodeModel2.DotNetNameFromLanguageSpecific(String LanguageName) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.CodeTypeDeclarationFromCodeClass(CodeClass vsClass) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnNamespacePopulateTypes(Object sender, EventArgs e) at System.CodeDom.CodeNamespace.get_Types() at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.Parse(TextReader codeStream) at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.System.CodeDom.Compiler.ICodeParser.Parse(TextReader stream) at System.CodeDom.Compiler.CodeDomProvider.Parse(TextReader codeStream) at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomDocDataAdapter.get_CompileUnit() at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) Need help!

    Read the article

  • C# and Metadata File Errors

    - by j-t-s
    Hi All I've created my own little c# compiler using the tutorial on MSDN, and it's not working properly. I get a few errors, then I fix them, then I get new, different errors, then I fix them, etc etc. The latest error is really confusing me. --------------------------- --------------------------- Line number: 0, Error number: CS0006, 'Metadata file 'System.Linq.dll' could not be found; --------------------------- OK --------------------------- I do not know what this means. Can somebody please explain what's going on here? Here is my code. MY SAMPLE C# COMPILER CODE: using System; namespace JTM { public class CSCompiler { protected string ot, rt, ss, es; protected bool rg, cg; public string Compile(String se, String fe, String[] rdas, String[] fs, Boolean rn) { System.CodeDom.Compiler.CodeDomProvider CODEPROV = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp"); ot = fe; System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters(); // Ensure the compiler generates an EXE file, not a DLL. PARAMS.GenerateExecutable = true; PARAMS.OutputAssembly = ot; foreach (String ay in rdas) { if (ay.Contains(".dll")) PARAMS.ReferencedAssemblies.Add(ay); else { string refd = ay; refd = refd + ".dll"; PARAMS.ReferencedAssemblies.Add(refd); } } System.CodeDom.Compiler.CompilerResults rs = CODEPROV.CompileAssemblyFromFile(PARAMS, fs); if (rs.Errors.Count > 0) { foreach (System.CodeDom.Compiler.CompilerError COMERR in rs.Errors) { es = es + "Line number: " + COMERR.Line + ", Error number: " + COMERR.ErrorNumber + ", '" + COMERR.ErrorText + ";" + Environment.NewLine + Environment.NewLine; } } else { // Compilation succeeded. es = "Compilation Succeeded."; if (rn) System.Diagnostics.Process.Start(ot); } return es; } } } ... And here is the app that passes the code to the above class: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string[] f = { "Form1.cs", "Form1.Designer.cs", "Program.cs" }; string[] ra = { "System.dll", "System.Windows.Forms.dll", "System.Data.dll", "System.Drawing.dll", "System.Deployment.dll", "System.Xml.dll", "System.Linq.dll" }; JTS.CSCompiler CSC = new JTS.CSCompiler(); MessageBox.Show(CSC.Compile( textBox1.Text, @"Test Application.exe", ra, f, false)); } } } So, as you can see, all the using directives are there. I don't know what this error means. Any help at all is much appreciated. Thank you

    Read the article

  • How to debug/break in codedom compiled code

    - by Jason Coyne
    I have an application which loads up c# source files dynamically and runs them as plugins. When I am running the main application in debug mode, is it possible to debug into the dynamic assembly? Obviously setting breakpoints is problematic, since the source is not part of the original project, but should I be able to step into, or break on exceptions for the code? Is there a way to get codedom to generate PDBs for this or something? Here is the code I am using for dynamic compliation. CSharpCodeProvider codeProvider = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } }); //codeProvider. ICodeCompiler icc = codeProvider.CreateCompiler(); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateExecutable = false; parameters.GenerateInMemory = true; parameters.CompilerOptions = string.Format("/lib:\"{0}\"", Application.StartupPath); parameters.ReferencedAssemblies.Add("System.dll"); parameters.ReferencedAssemblies.Add("System.Core.dll"); CompilerResults results = icc.CompileAssemblyFromSource(parameters, Source); DLL.CreateInstance(t.FullName, false, BindingFlags.Default, null, new object[] { engine }, null, null);

    Read the article

  • Using Linq methods causes missing references to DependencyObject in WindowsBase

    - by Jason Coyne
    I have some c# source that I want to compile using CodeDom within my application (for a plugin) Everything works fine, except if I use a Linq extension function on some of my collections var dict = new Dictionary<KeyType, ValueType>(); .... dict.Any(KV=>KV.Key == "Some Key); When I try to compile source that has this code, it CodeDom complains that I am missing a reference to DependencyObject in WindowsBase. I do not understand why this is happening. Neither the Dictionary class, or the Any extension method reference that class, which apparently is part of Windows.Forms I would normally just ignore the quirk, make the CodeDom add a reference and move on, but Apparently WindowsBase is special and is not always distributed and I don't want to cause issues for users that may not have it installed correctly.

    Read the article

  • How to test a BuildProvider

    - by michielvoo
    I have created a simple BuildProvider as a starting point, and althogh I get no errors, I don't have access to the generated class either. In fact, i don't know if my BuildProvider was even invoked. Is there a way to debug a BuildProvider? How do I know if there is a problem with my CodeDom or if it's something else? Thanks!

    Read the article

  • Is any simple way to create method and set its body dynamically in C#?

    - by greatromul
    I hold body of method in string. I want to create method dynamically. But I don't know, how to set its body. I saw very tedious way using CodeDom. And I saw using Emit with OpCodes. Is any way to use ready code from string variable? string method_body = "return \"Hello, world!\";"; //there is method body DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("My_method", typeof(string), new Type[] { }); //any way to create method dynamically //any way to set body string result = (string)dm.Invoke(...); //I need write result in variable

    Read the article

  • How to use CodeDomSerializer to serialize an object in .Net?

    - by user341127
    I have a class, which is defined as the following: [ToolboxItem(false)] [DesignTimeVisible(false)] [DesignerSerializer("DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer, DevExpress.XtraEditors.v10.1.Design", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design")] [Designer("DevExpress.XtraEditors.Design.BaseRepositoryItemDesigner, DevExpress.XtraEditors.v10.1.Design")] [LicenseProvider(typeof(DXEditorLicenseProvider))] public class RepositoryItem : Component, ISupportInitialize, ICustomTypeDescriptor, IImageCollectionHelper {......} I tried the following code to serialize the object of this class. DesignerSerializationManager m = new System.ComponentModel.Design.Serialization.DesignerSerializationManager(); m.CreateSession(); DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer s = m.GetSerializer(typeof(RepositoryItem), typeof(DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer)) as DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer; RepositoryItem i = persistentRepository1.Items[0]; //m.Container.Add(i); s.Serialize(m,i );// An error "Object reference not set to an instance of an object." happended here. For I am not familiar with CodeDom, I have spent one day to get the way out. I guess the above code has some stupid mistakes. Please give me a hand to show how to serialize AND DeSelialize such objects of the class of Repository. BTW, the reason I don't use any other serializer is that I am supposed not to have rights to know the source code of RepositoryItem and others could inherit RepositoryItem at the same time. And actually I have to deal with RepositoryItem and its descendants. Thank you in advance. Ying

    Read the article

  • Issue with VS 2008 designer and usercontrol.

    - by Ram
    Hello, I have created a custom data grid control. I dragged it on windows form and set its properties like column and all & ran the project. It built successfully and I am able to view the grid control on the form. Now if i try to view that form in designer, I am getting following error.. Object reference not set to an instance of an object. Instances of this error (1) 1. Hide Call Stack at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.GetMemberTargetObject(XmlElementData xmlElementData, String& member) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateAssignStatement(XmlElementData xmlElement) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement() at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e) at System.CodeDom.CodeMemberMethod.get_Statements() at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) If I ignore the exception, form appears blank with no sign of grid control on it. However I can see the code for the grid in the designer file. Any pointer on this would be a great help.

    Read the article

  • VS 2008 designer and usercontrol.

    - by Ram
    Hello, I have created a custom data grid control. I dragged it on windows form and set its properties like column and all & ran the project. It built successfully and I am able to view the grid control on the form. Now if i try to view that form in designer, I am getting following error.. Object reference not set to an instance of an object. Instances of this error (1) 1. Hide Call Stack at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.GetMemberTargetObject(XmlElementData xmlElementData, String& member) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateAssignStatement(XmlElementData xmlElement) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement() at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader) at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e) at System.CodeDom.CodeMemberMethod.get_Statements() at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) If I ignore the exception, form appears blank with no sign of grid control on it. However I can see the code for the grid in the designer file. Any pointer on this would be a great help. I have customized grid for my custom requirements like I have added custom text box n all. I have defined 3 constructors public GridControl() public GridControl(IContainer container) protected GridControl(SerializationInfo info, StreamingContext context)

    Read the article

  • CSharpCodeProvider: Why is a result of compilation out of context when debugging

    - by epitka
    I have following code snippet that i use to compile class at the run time. //now compile the runner var codeProvider = new CSharpCodeProvider( new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } }); string[] references = new string[] { "System.dll", "System.Core.dll", "System.Core.dll" }; CompilerParameters parameters = new CompilerParameters(); parameters.ReferencedAssemblies.AddRange(references); parameters.OutputAssembly = "CGRunner"; parameters.GenerateInMemory = true; parameters.TreatWarningsAsErrors = true; CompilerResults result = codeProvider.CompileAssemblyFromSource(parameters, template); Whenever I step through the code to debug the unit test, and I try to see what is the value of "result" I get an error that name "result" does not exist in current context. Why?

    Read the article

  • C# compiler error CS0006: metadata file is not found

    - by Rob
    I've built a c# compiler using the tutorial on MSDN and a few other resources including here, and I've gotten it to work until I add additional reference assemblies. My errors stem from adding "System.dll" and "System.Windows.Forms.dll" to the ReferenceAssemblies list. here's my code: private void SetUpCompilingParameters() { string ver = string.Format("{0}.{1}.{2}", Environment.Version.Major, Environment.Version.MajorRevision, Environment.Version.Build); string libDir = string.Format(@"{0}", Environment.CurrentDirectory); string raDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"; string exWpfDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}\WPF", ver); string exDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}", ver); MyCompiler = new CSharpCodeProvider(); CompilingParam = new CompilerParameters(); CompilingParam.GenerateExecutable = false; CompilingParam.GenerateInMemory = true; CompilingParam.IncludeDebugInformation = false; CompilingParam.TreatWarningsAsErrors = false; CompilingParam.CompilerOptions = string.Format("/lib:{0}", libDir); CompilingParam.CompilerOptions = string.Format("/lib:{0}", raDir); CompilingParam.CompilerOptions = string.Format("/lib:{0}", exDir); //CompilingParam.CompilerOptions = string.Format("/lib:{0}", exWpfDir); CompilingParam.ReferencedAssemblies.Add("System.dll"); CompilingParam.ReferencedAssemblies.Add("System.Windows.Forms.dll"); } As you can see, I've explicitly referenced directories in CompilerOptions but its not helping. I'd like to test the solution on here on stackoverflow that utilizes: CompilingParam.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location); but I'm having trouble using it for the general System.dll etc...

    Read the article

  • How do I access the CodeDomProvider from a class inheriting from Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGeneratorWithSite?

    - by Charlie
    Does anyone know how to get a CodeDomProvider in the new Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGeneratorWithSite from the Visual Studio 2010 SDK? I used to get access to it just by in mere inheritance of the class Microsoft.CustomTool.BaseCodeGeneratorWithSite, but now with this new class it is not there. I see a GlobalServiceProvider and a SiteServiceProvider but I can't find any example on how to use them. Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGeneratorWithSite: http://msdn.microsoft.com/en-us/library/bb932625.aspx I was to do this: public class Generator : Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGeneratorWithSite { public override string GetDefaultExtension() { // GetDefaultExtension IS ALSO NOT ACCESSIBLE... return this.InputFilePath.Substring(this.InputFilePath.LastIndexOf(".")) + ".designer" + base.GetDefaultExtension(); } // This method is being called every time the attached xml is saved. protected override byte[] GenerateCode(string inputFileName, string inputFileContent) { try { // Try to generate the wrapper file. return GenerateSourceCode(inputFileName); } catch (Exception ex) { // In case of a faliure - print the exception // as a comment in the source code. return GenerateExceptionCode(ex); } } public byte[] GenerateSourceCode(string inputFileName) { Dictionary<string, CodeCompileUnit> oCodeUnits; // THIS IS WHERE CodeProvider IS NOT ACCESSIBLE CodeDomProvider oCodeDomProvider = this.CodeProvider; string[] aCode = new MyCustomAPI.GenerateCode(inputFileName, ref oCodeDomProvider); return Encoding.ASCII.GetBytes(String.Join(@" ", aCode)); } private byte[] GenerateExceptionCode(Exception ex) { CodeCompileUnit oCode = new CodeCompileUnit(); CodeNamespace oNamespace = new CodeNamespace("System"); oNamespace.Comments.Add(new CodeCommentStatement(MyCustomAPI.Print(ex))); oCode.Namespaces.Add(oNamespace); string sCode = null; using (StringWriter oSW = new StringWriter()) { using (IndentedTextWriter oITW = new IndentedTextWriter(oSW)) { this.CodeProvider.GenerateCodeFromCompileUnit(oCode, oITW, null); sCode = oSW.ToString(); } } return Encoding.ASCII.GetBytes(sCode ); } } Thanks for your help!

    Read the article

1 2 3 4  | Next Page >