I have an application developed in Visual Studio 2010 incorporating the CSLA.Net framework and FileHelpers Library.
I am using the code below to read a csv file with the file helpers library. I have break points set on every line and it faults after the engine.BeginReadFile. I have tried both csv and txt files on the read function. I even commented out the method i have and used the sample method from filehelpers along with their sample code and received the same error. The code will not progress beyond the engine.BeginReadFile method. It does not make it to the foreach loop at all. the error i receive is :
System.Exception._COMPlusExceptionCode -532462766
I am not very familiar with Visual Studio, but I cannot find any further breakdown of this error. the code in question is below.
using (FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof(ProductionSchedule)))
{
// To Read Use
engine.BeginReadFile(filename);
foreach (ProductionSchedule prodsched in engine)
{
// get the connection string properly once a database is available
using (SqlConnection connection = new SqlConnection(Settings.Default.ConnectionString))
{
You are using the Async engine but you are not waiting for it to complete from the brief snippet you have given above.
Based on these assumptions, I would suspect that you are attempting to iterate through the collection as it's being changed. Either that or your SQL ConnectionString is invalid.
Related
I have tried below two methods and ensured that license is updated along with the correct binary. Using .net framework 4.5.2. Below using doc.save method is not working.
Option 1:
doc.Save(LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype,SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);
Option 2:
doc.Save(this.Response, "LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype", ContentDisposition.Inline, null);
Acccording to the documentation, there are several overloads of the method Document.Save() that you can use :
https://apireference.aspose.com/words/net/aspose.words/document/methods/save/index
However make sure that you are not locking the file you read (after opening the file and executing your program at the same time).
You must use one stream (MemoryStream) for reading and another one for writing.
Also make sure Visual Studio (run as admin) have access to the location where you try to write the file at, in case you run the program from Visual Studio.
What I am trying to do is:
I have a Asp Mvc website. In it I need to create a function that does the following:
converts a .dwg (AutoCad) file to a .pdf file
converts a .dwg file to a .dwf file
I started with the, what I tought at the time, easier task to have the .dwg to a .pdf. After some research I found out that a way to do that (without buying a 3rd party license) is to install TrueView on the server and using it (or actually a AcCtrl.dll) to convert the file. Well, I did so. I installed the True View program and added a reference to AcCtrl Component (ACCTRLLib). Then I added a reference to the Dll inside the class file I am working on:
using ACCTRLLib;
So far so good. After that I followed the instructions on this post: PDF conversion using dwg true viewer in VB6
First, this is my code:
public static void ConvertFile()
{
IAcCtrl contrl = new AcCtrl();
contrl.PutSourcePath(#"D:\MMA\Autocat\File1.dwg");
string[] pdfPath = new string[1] { #"D:\MMA\Autocat\File1.dwg" };
contrl.SilentPublish(pdfPath);
}
Then, according to the post, I went to see if there is a registry with the specified path. The path that I have as a registry is the following:
HKEY_CURRENT_USER\Software\Autodesk\DWG TrueView\R13\DWGVIEWR-E001:409\Profiles\<<\Unnamed Profile>>\Dialogs\AcPublishDlg
So, I created a 'String Value' in it with ValueName: Location and ValueData: D:\MMA\Autocat\Testing
Alright. So, thats it. After all that I ran the application and called the function. The debugger goes through the code and everything executes (or at least looks like so) but nothing happens. I don't get a file in the D:\MMA\Autocat\Testing folder. I get no exception, no warning nothing. It just executes and nothing happens.
So what else did I tried. Some of those things might be a little naive or silly to try but nevertheless I did as I happen to be a little desperate.
I tried everything in a console application. I wasnt completely sure that this method is suitable for ASP MVC so I tried the same code with a console application unfortunatelly to the same result.
I added a file name inside the location string value. I changed the Location ValueData from 'D:\MMA\Autocat\Testing' to 'D:\MMA\Autocat\Testing\testFile.pdf' as I noticed that nowhere in the whole process a file name is asked for the converted file.
Following my thought from the previous conclusion I tried to supply the path to the 'result' file to the SilentPublish function.
string[] pdfPath = new string[1] { #"D:\MMA\Autocat\Testing\testFile.pdf" };
contrl.SilentPublish(pdfPath);
Again to no avail. So, my question, or rather questions are:
Is it possible to do it this way and if it is what am I doing wrong?
If its not than can you suggest a way?
Also if a .dwg to .dwf conversion is possible (with the same or different method I am all ears)
Thank you very much
True View does not expose the Autodesk.AutoCAD.PlottingServices namespace. You're going to need either a licensed copy of AutoCAD, RealDWG, or another third party API.
I'm not sure if you are still having this issue, but you should be able to do this with the Autodesk Forge API. Calls can be made from any language with a simple HTTP call. You will have to first convert to SVF and then to DXF and PDF from there.
I have a MS Access Database that has a button on it that is supposed to run a tool that I wrote. The tool works. The Access DB works. The VBA to run the tool works.
However, there is an issue when running the tool from VBA. It always crashes when trying to load XML configuration data. I tested this by checking my Error Reporting tool (Control Panel -> Administrative Tools -> Event Viewer). I also wrote a second version of my tool which has all of the XML data hard-coded into it.
I am wondering if there is a known reason for this to occur, and if there is a workable solution for getting around this error. Hard-coding all of my configuration data is not really an ideal solution, as the configuration data needs to be modifiable without having to recompile the entire project and push out an update.
Information:
MS Access 2010 with Visual Basic for Applications (using Shell for
application calling)
C# application with XML configuration data using references (IO, Linq, Xml.Linq, Data.OleDb, Globalization)
Thanks for any assistance you may be able to offer.
Per request, here is the code I use to run the application:
Dim hProcess As Long
Dim myPath As String
dim myFile As String
myPath = Environ("ProgramFiles(x86)" & "\mytool\"
myFile = "mytool.exe"
hProcess = Shell( myPath & myFile, vbNormalFocus )
The application is a WinForms application that allows the user to map column names in a csv to fields in access. The only actual issue is the part where it attempts to load the XML configuration data:
XDocument xDoc = XDocument.Load(Environment.CurrentDirectory + "\\config.xml");
Again, if I hard-code the configuration data into the application itself, there is no issue at all when running the application. However, if I attempt to load the XML configuration data, it gives an Error Event in the Event Viewer stating that there was an unhandled exception when loading the XML file. If I run the application outside of the VBA Shell call, it runs fine and can load the XML file. It only ever crashes when trying to load the XML from VBA Shell.
In my experience, executing .NET code from MS Access seems to "mess up" some of .NET's "get the current directory" methods, which all work fine if you run the exact same .NET application directly without Access.
If you want to see what I'm talking about, create a new console application in Visual Studio and paste the following code:
using System;
using System.IO;
namespace CurrentDirTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Environment.CurrentDirectory);
Console.WriteLine(Directory.GetCurrentDirectory());
Console.WriteLine(System.Threading.Thread.GetDomain().BaseDirectory);
Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
Console.ReadLine();
}
}
}
When I run that directly from Visual Studio, it outputs this (as expected):
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug\
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug\
Now put the compiled .exe in your Program Files (x86)\mytool\ folder and try to call it from Access, with the VBA code from your question.
When I do that on my machine, I get this:
C:\Users\MyUserName\Documents
C:\Users\MyUserName\Documents
C:\Program Files (x86)\mytool\
C:\Program Files (x86)\mytool\
Weird, isn't it?
Environment.CurrentDirectory and Directory.GetCurrentDirectory() both return my "Documents" folder as soon as the application is executed from MS Access.
I've got no idea why this happens, but it does.
Solution:
If you get the same results on your machine as I do on mine, the solution for your problem is simple: just use System.Threading.Thread.GetDomain().BaseDirectory or AppDomain.CurrentDomain.BaseDirectory to get the current directory.
Just in case someone has a similar problem when using COM-Interop:
The problem is even worse when you execute a .NET assembly via COM-Interop from MS Access.
If I recall it correctly, both System.Threading.Thread.GetDomain().BaseDirectory and AppDomain.CurrentDomain.BaseDirectory didn't work for me either because both returned the directory of the msaccess.exe.
I had to use this.GetType().Assembly.Location to get the actual location of the .NET assembly.
I think it is simple to do this but i dont know how to start? I want to get layer name or label name in the autocad file using c#. I search the forums but i really find anything valuable. I found the ObjectARX and AutoLisp, but i dont find any tutorial about theese API's. So, i want to simple example about the reach autocad file.
If you downloaded the ObjectARX SDK from the official site it contains many sample projects to get you started. You will need to have some AutoCAD knowledge to understand the structure of the .dwg database as exposed by the API. Be prepared to invest significant time in the project.
If you just are looking for a simple one time dump of the data in a .dwg file ask your local drafter as there is a command in the AutoCAD UI for doing this known as the Data Extraction Wizard.
Another answer on stackoverflow recommend this book chapter as a way to understand the AutoCAD database connection features.
It's simple as follows:
[CommandMethod("LayerIterator")]
public static void LayerIterator_Method()
{
Database database = HostApplicationServices.WorkingDatabase;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
SymbolTable symTable = (SymbolTable)transaction.GetObject(database.LayerTableId, OpenMode.ForRead);
foreach (ObjectId id in symTable)
{
LayerTableRecord symbol = (LayerTableRecord)transaction.GetObject(id, OpenMode.ForRead);
//TODO: Access to the symbol
MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
}
transaction.Commit();
}
}
Details can be found from http://spiderinnet1.typepad.com/blog/2012/06/autocad-net-iterate-through-layer-table.html
We have a code generator that munges the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file.
In the code to munge all the strings, we try and keep on top of the indenting and formatting as much as possible, but invariably when you come to open the file in Visual Studio the formatting is awry. A quick ctrl-k, ctrl-d fixes it, but obviously this reformatting is lost the next time the class is generated.
What I'd like to know, is if there's a way I can somehow automatically format the contents of the textfile in the same way Visual Studio does?
Pseudocode
Create "code" object, passing text file to constructor
Invoke "format" method
Re-save text file
Any help greatly appreciated.
EDIT:
I should clarify - I want to be able to invoke the formatting from my C# code that creates the textfile containing my generated C#. The format of the code can be standardised (doesn't have to be per-developer), and I don't want to have to install any 3rd-party apps.
I seem to remember there's a namespace containing loads of classes for creating C# in C#: http://msdn.microsoft.com/en-us/library/system.codedom(VS.80).aspx, but I'm not sure if it contains any classes that could help.
FURTHER EDIT:
My code generator is a winforms app deployed via a click-once install. It's used by many developers in-house. I need a solution that doesn't require each developer to have a tool installed on their machine.
To properly indent code programmatically you would need Microsoft.CodeAnalysis.CSharp nuget package and .NET framework 4.6+. Sample code:
public string ArrangeUsingRoslyn(string csCode) {
var tree = CSharpSyntaxTree.ParseText(csCode);
var root = tree.GetRoot().NormalizeWhitespace();
var ret = root.ToFullString();
return ret;
}
One-liner:
csCode = CSharpSyntaxTree.ParseText(csCode).GetRoot().NormalizeWhitespace().ToFullString();
You may also use NArrange to sort methods in your cs file, organize usings, create regions, etc. Note that NArrange does not indent anything.
Take a look at Narrange.You'll probably need to automate these things as part of the build.
Not sure if it meets all your requirements though.
To quote:
NArrange is a .NET code beautifier
that automatically organizes code
members and elements within .NET
classes.
You can use CodeDOM and the CSharpCodeProvider. It is all in the namespaces Microsoft.CSharp and System.CodeDom.
Her is an example of a property:
StringWriter writer = new StringWriter();
CSharpCodeProvider provider = new CSharpCodeProvider();
CodeMemberProperty property = new CodeMemberProperty();
property.Type = new CodeTypeReference(typeof(int));
property.Name = "MeaningOfLifeUniverseAndEverything";
property.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(42)));
provider.GenerateCodeFromMember(property, writer, null);
Console.WriteLine(writer.GetStringBuilder().ToString());
This code will generate:
private int MeaningOfLifeUniverseAndEverything {
get {
return 42;
}
}
The CodeDOM is a quite chatty way to generate code. The good thing is that you can generate multiple languages. Perhaps you can find a Erlang.NET CodeProvider?
You might be able to do a few shortcuts by using CodeSnippetExpression.
Only if you're running the code generator as a VS add-on - each developer is going to have different settings.
Here's how to do it from the context of a macro or add-in:
var dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0");
dte.ExecuteCommand("File.OpenFile", filename);
dte.ExecuteCommand("Edit.FormatDocument", filename);
dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesYes);
Warning: As #Greg Hurlman says, the output will vary depending on the user's current options.
Edit:
unfortunately your method requires me to have an instance of VS running alongside my winforms app. Can you think of a way to create an instance of VS from within my app (if that's even possible)?
I think it might be possible to do from within your Win.Form app. However, you'll have to have Visual Studio installed on the machine running the code.
Try this:
var dte = (EnvDTE80.DTE2)Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.8.0", "");
dte.ExecuteCommand("File.OpenFile", filename);
dte.ExecuteCommand("Edit.FormatDocument", filename);
dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesYes);
Keep in mind that you'll need references to the EnvDTE80.dll assembly.