Tuesday

to fix circular reference was detected while serializing an object:

in a c# - in all sub classes find reference to parent class and add
[XmlIgnore] attribute.
Bad news is that you have to do that for all objects every time dbml file was changed.
So I have create simple python script that do this for me:



import os
import re

file_to_patch='LinqDataObjects.designer.cs'
bak_file='LinqDataObjects.designer.cs.bak'
os.rename(file_to_patch,bak_file)

fileHandle = open ('linesToPatch.txt')
linesToPatch = fileHandle.readlines()

f = open(bak_file)
new_file=open(file_to_patch, 'w')
new_file.write("using System.Xml.Serialization;\n")

for aline in f:
new_file.write(aline)
for rline in linesToPatch:
if aline.strip() == rline.strip():
new_file.write("\t[XmlIgnore]\n")
break




linesToPatch.txt - is simple text file that contains all lines those must have XMLIgnore, for example:


[Association(Name="Invoice_AccountFee", Storage="_Invoice", ThisKey="InvoiceID", OtherKey="InvoiceID", IsForeignKey=true)]
[Association(Name="Accounts_basic_AccountInvoice", Storage="_Accounts_basic", ThisKey="CustomerID,SubID", OtherKey="customer_,sub", IsForeignKey=true)]
[Association(Name="Invoice_AccountInvoice", Storage="_Invoice", ThisKey="InvoiceID", OtherKey="InvoiceID", IsForeignKey=true)]
[Association(Name="AccountFeeType_AccountFeeSubType", Storage="_AccountFeeSubTypes", ThisKey="FeeTypeID", OtherKey="stFeeTypeID")]

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...