ASP.NET MVC 2 bug, misleading exception message

by Syska 29. March 2010 00:11

Today I was making some refactoring to my site made in ASP.NET MVC 2. Created a complex class on my  model, which should be passed to a RenderPartial like this:

<% Html.RenderPartial(“name”, Model.ComplexClass) %>

Corrected the type in the partial view I was expecting but got an odd error I think …

The model item passed into the dictionary is of type 'Model.MyModel', but this dictionary requires a model item of type 'Model.ComplexClass'.

So I started to look around, but got even more confused … recompiled, open and closed Visual Studio 2008, until I found the error. The reference to the ComplexClass was null. I’m not sure why it thinks it got a type of the model instead of the my ComplexClass.

This got to be a bug or something to do with the Reflection methods used to determine the type of the class passed to the PartialRender when trying to cast it and that failed. So when throwing the Exception, the information could be wrong … only guesses.

Update:
Searched the internet, and one person suggested parsing the values to the "ViewDateDictionary" ... but still not a good workaround here.

Tags: , ,

Tech-Ed Europe 2009 round up

by Syska 22. November 2009 19:46

As a MSP, we were invited to join Tech-Ed Europe 2009 conference, in which we were 3 Danish MSP’s that accepted that offer, that was Jacob Korsgaard, Allan Juhl Petersen and Mikael Syska (myself).

As I missed the first flight, cause I read the departure time wrong (god damn). I first arrived Monday morning 8:30 in Berlin, and then had to go to the Hotel with my luggege and just to get a shower, cause I smelled like crap after spending the night in the Airport.

I then took the S-Barn to the South entrance to Messe Berlin, and I then thought I was maybe one of the last people to arrive, but I was wrong.

As you can see on the picture above, there were lost of people arriving the same time as me, so after all, I was not that late at the first day, even though I missed the flight I was supposed to have taken.

 

When I entered the registration room, holy fuck there were many people waiting to get there badge. But it went fairly quickly. But then … 3 people in front of me, there were some problems with a persons registration and it took like 30 minutes (excluding to the 10 minutes i had allready spend in the queue, where 100 people had completed there registration) before they send him over to  another booth, where I guess they can see some additional information about the attendees. There must have been something completely wrong, I don't know. But at last I got in … weeeee.

The keynote the first day was about “The new Efficiency”. In short terms, its about cost savings, productivity and innovation. They talked about where companies have used Microsoft products to achieve these 3 goals.

Don’t got a phone with wireless access, no problem. There were plenty of computers freely available to use, and also access to a printer. So you could plan your schedule or maybe just print it, if you forgot to do it at home.

So … does we only listen to speakers, talk with other developers … not at all, 2 days at the conference there were beers, wine and food. That’s nice, and while you were having a drink you could also walk around and talk to the different speakers, exhibitors and of cause  all the other attendees.

Two of the Danish MSP won the AntMe battle, Jacob(with the WOW game in his hands) and then Allan, the 2 persons to the left on the picture. Though out the week, at the Community lounge, you were given the opportunity to program the Ants what they should do, collect food, kill bugs or attack the other ant colonies. There goals were clear … kill kill kill after they watched a demo and there strategy gave them the victory. The biggest problem was to get the game back to Denmark, because it was so big. But our ADE, Martin Esmann knew a danish guy that had traveled by car to Tech-Ed Europe, so he could bring it with him is the car to Denmark.

Yes, there are also Band Hero is here … I guess its all over the world now.

So what else did I see at the conference.

In the future I will blog about the following

Windows 7

Mostly tip and tricks ... and what i find usefull in Seven.

Hyper-V R2

How my the reinstallation of my Windows Server 2008 to Windows Server 2008 R2 went. The people at the virtualization booth said that the preferred way was to reinstall the system completely to avoid any problems. Then just export the guess systems that are running, and afterwards import them again.

Visual Studio 2010 Team Foundation Server

I have never used VSTS, but as I attended a few of the sessions about it, I could understand that the 2010 version is way better. MS people has to say this of cause, but other attendees were also very positive of 2010 and the new features are great.

  • Graphical administration, instead of small console apps.
  • Integrated Rollback are also supported now. Undo of rollback are not supported but as they said, you can rollback to a previously version to get the same effect. So rollback a rollback … that's like a undo :-)
  • Better integration into Visual Studio, braches, setup etc.
  • Installation in less than 20 minutes.
  • And even more I will look into later.

MSSQL 2008 Spatial Data

I attended a session about spatial data in SQL and what you have to watch out for and how to debug performance problems. If I get the time I will try to make a little sample app in WPF with a SQL server with spatial data. But not sure I get the time. If one ever want to use map data, this is the way to go. So easy to do mapping etc.

WPF - Windows Presentation Foundation

As I have started learning WPF, I will blog about some of the nice and bad things I find.

What i missed were at TechEd Europe 2009

  • Something about Silver light 4
  • Internet at the hotel
  • Shorter distance between all the halls and soda and coffee close to the sessions.
  • That we did not get the bottle to have water in, so we had to get our own, totally odd.

My over all score is 4/5

The next time i attend such a big conference, I will have more knowledge how to spend my time and not waste it on session I think could be interesting. Then just skip it and and use the time with the exhibitors booths.

yoda

Tags: , , ,

Microsoft Visual Studio 2010 BETA2 Available for download

by Syska 20. October 2009 08:50

So the other day I was talking to my fellow MSP’s(Microsoft Student Partner) if some of of was using VS 2010. Most of us had tried the beta but not really used it cause it still had a slow UI, which should be fixed in the next release, BETA2.

So while writing this, I also began the installation of: Visual Studio 2010 Ultimate Beta 2 Web Installer (x86) - (English). Instead of downloading the normal ISO image, I would try the Web Installer this time. More on that later how it went.

I will later write something about the new features as I start using Vs 2010. For now just take a look at this link: Visual Studio 2010 and .NET Framework 4 Beta 2 Walkthroughs

Tags: , , ,

MailScannerWatermark Plugin For Microsoft Exchange 2007

by Syska 7. August 2008 19:42

If you have more offsite Exchange 2007 installations and dont want to route all mail traffic to the MailScanner box itself to save bandwidth, this is the perfect solution.

Please contact me if there are any missing options in the implementation.

Index

  • How to install the MailScannerWatermark plugin for Microsoft Exchange 2007
  • How to uninstall a TransportAgent for Microsoft Exchange 2007
  • Conclusion
  • Files

How to install the MailScannerWatermark plugin for Microsoft Exchange 2007

File are placed in the bottom.

1st step

Extract the content of the zip archive. The content should look something like below.

Filestructure

  • MailScannerWatermark 
    • AgentProject ( source code )
    • MS Files
      • Microsoft.Exchange.Data.Common.dll
      • Microsoft.Exchange.Data.Transport.dll
    • Files
      • Create.Event.Source.ps1
      • MailScannerWatermark.dll
      • Settings.reg
Copy "MailScannerWatermark.dll" from the "Files" directory to a folder on the Microsoft Exchange 2007 server. I have used "C:\IfYouDo.Net\" and placed the file there. You may use whatever directory you want.

2nd step

Install the plugin with the following command in the Power Shell:

[PS] C:\>install-transportagent

cmdlet install-transportagent at command pipeline position 1
Supply values for the following parameters:
Name: MailScannerWatermark
TransportAgentFactory: IfYouDo.Net.MailScannerWatermarkFactory
AssemblyPath: C:\IfYouDo.Net\MailScannerWatermark.dll

Identity                                           Enabled         Priority
--------                                           -------         --------
MailScannerWatermark                               False           10
WARNING: Please exit Powershell to complete the installation.
WARNING: The following service restart is required for the change(s) to take
effect : MSExchangeTransport


Notes:

  • The AssemblyPath must to changed acordingly to the FolderPath used in step 1.
  • Make sure the permissions are right on the assembly file else it will complain about the Path are incorrect.

3rd step

Enable the plugin in Power Shell with:

[PS] C:\>Enable-TransportAgent MailScannerWatermark

4th step

In the folder used above, there should be a file named "settings.reg", double click it to register the values to the register database and then edit the values or do it manualy before with notepad or similar program:

Change the values to suit your needs:

 Debug  True/False
 HeaderName  HeaderName used in the MailScanner installation, excluding the ":" (colon). The HeaderName will be trimmed for any ":" in the end, just to make sure no one just copies the HeaderName from the MailScanner settings.
 Secret  The secret used in the Mailscanner installation, if MultipleDomains are "False"
 Expiry  How many days the Watermark is valid.
 MultipleDomains  True/False. If "True", it will look for the domain in the regdb, and use that secretkey if found. If the domain is not found, and "Secret" is in the regdb it will use that secretkey else it will just skip that domain. If "False" it will use "Secret" value as key for all doamins.
 domainname.tld  secretkey

Example 1 - Same secret for all domains.

Example 2 - domain1.com and domain2.com have diff keys but "Secret" are used for all others

Remove the "Secret" key from the regdb, if you dont want other domains than domain1.com and domain2.com to get tagged with a Watermark.

5th step

Run the following command in the Power Shell to restart the Microsoft Exchange Transport.

[PS] C:\>Restart-service MSExchangeTransport

6th step

Run the "Create.Event.Source.ps1" from the Files folder, this will create an EvenLog Source "MailScannerWatermark" in the Application log.

7th step

First ... use debug ... there will be  some info about the time found, msgid, etc. so we know its right.

Then send an email to a valid recipient, to see that the watermark is actually there.
Then send an email to an invalid recipient, that you know will send a message back to you, and make sure its get a NDR.
Then telnet to a public ISP SMTP server, and make a fake email, that we know will not get a valid watermark.

All text below with a "C:" before the line are client commands, and needs to be written by you, the others are server responses.

Make a "telnet" connected to a smtp. Like the below if you are running Windows. The prompt may differ a little.
cmd> telnet some.smtp.tld 25
S: 220 smtp.example.com ESMTP Postfix
C: HELO relay.example.org
S: 250 Hello relay.example.org, I am glad to meet you
C: MAIL FROM:<bob@example.org>

S: 250 Ok
C: RCPT TO:<alice@example.com>
S: 250 Ok
C: RCPT TO:<theboss@example.com>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: Subject: Test message
C: Hello Alice.
C: This is a test message
C: Your friend,
C: Mikael Syska
C: .
S: 250 Ok: queued as 12345
C: QUIT
S: 221 Bye


The above example should be with a valid from address and an invalid recipient address, so we will get a NDR, but this time it should be taken by the MailScanner server, since it does not contain a valid Watermark.

How to uninstall a TransportAgent for Microsoft Exchange 2007

1st Step

Will give you a list of all installed transportagents

[PS] C:\>transportagent
Identity                                           Enabled         Priority
--------                                           -------         --------
Transport Rule Agent                               True            1
Journaling Agent                                   True            2
Connection Filtering Agent                         True            4
Content Filter Agent                               True            5
Sender Id Agent                                    True            6
Sender Filter Agent                                True            7
Recipient Filter Agent                             True            8
Protocol Analysis Agent                            True            9
MailScannerWatermark                               True            10


2nd Step

From the list above, I have choosen to uninstall the "MailScannerWatermark" plugin.

[PS] C:\>uninstall-transportagent MailScannerWatermark

Confirm
Are you sure you want to perform this action?
Uninstalling Transport agent "MailScannerWatermark". A service restart is
required for the change to take effect.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):


Type "Y" to confirm that you want to uninstall it

3rd Step

Run the following command in the Power Shell to restart the Microsoft Exchange Transport.

[PS] C:\>Restart-service MSExchangeTransport

Now the plugin is uninstalled from the system.

Conclusion

This have been very fun to play with Microsoft new Transport-Agents in Exchange 2007. There are very powerfull and there are endless ideas of what you can do now ... in a very easy way compared to Event Sinks in Exchange 2003.

Any comments are most welcome ...

Note: This could be made to work with EventSinks also in Exchange 2003, but I dont have the knowledge nor time to do it ... if someone makes it, I will happily post it here.

Files

Old version will be taken offline and will not be available.

Version Download Changes
v.2 MailScannerWatermark.zip (617.01 kb) Updated to support multiple "Secrets"
v.1 MailScannerWatermark.zip (612.53 kb) First version

Tags: , , , , ,

Project

About the brain

Mikael SyskaMikael Syska

Student at the Engineering College of Aarhus.

Microsoft Student Partner ( MSP )

On this blog I will primarily write about .NET, MSSQL & projects I'm working on ... and of course there will some off topic posts :-)