Kevin Grohoske

Vice President of Software Engineering / Senior Software Engineer 
MCPD-WEB, MCPD-WIN, MCSD

System.BadImageFormatException When Using InstalUtil

Thursday, October 04, 2007 04:28 | posted by: kevin

Quick Tip:

If you get a System.BadImageFormatException when trying to install a Windows Service with the InstalUtil.exe utility. Make sure you are not accidentally using the VS 2003 or older version of the Command Prompt.

Tags:

PermaLink   E-Mail Article   RSS Comment Feed  

Using Dictionary Object Params In Your Web Service

Friday, September 07, 2007 04:14 | posted by: kevin

In neither .NET Framework 2.0 or 1.x can dictionary objects be used parameters for web service methods, because they are serializable.

For example the following will compile, but not work:

[WebMethod]public string MyMethod(Dictionary<string></string> CustomArguments)

You will generate the following runtime error when you test the ws:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.

Don’t dispair I found a great option that will work!!

On Paul Welter’s Weblog

He has an example of a Serializable Dictionary Object. Copy this code into a new class, change your method signature to:

[WebMethod] public string MyMethod(SerializableDictionary<string></string> CustomArguments) { return "Success"; }

Then to use it copy or reference the class on the client side and simply do the following:

localhost.MyService wsService = new localhost.MyService(); SerializableDictionary<string></string> dict = new SerializableDictionary<string></string>(); //use it like any dictionary object dict.Add("test","me"); //call the method of the web service with the dictionary object serialized wsService.MyMethod(dict);

Note: I have noticed that when I use this method sometimes I will get compile errors that imply that I am trying to pass a DataSet rather than the SerializableDictionary object. To correct this manually go into the references.cs and change the method signatures from DataSet to SerializableDictionary. That should fix the problem.

Tags:

PermaLink   E-Mail Article   RSS Comment Feed  

Yesterday I was trying to help a co-worker that had an odd problem in their ASP.NET 2.0 application. Despite the fact that the class was in the ‘App_Code’ directory and the class was within the same namespace yet it could not accessed/recognized. We were receiving the error, “The type or namespace name ‘example’ could not be found (are you missing a directive or an assembly reference?)”.

Working through the issue I found some interesting possible issues.

1. I could not delete and create a new ‘App_Code’ directory. When I right clicked the project, chose Add, and chose Add Folder, there was no listing for the App_Code folder.

2. I though that perhaps the ‘App_Code’ directory was created incorrectly, due to issue #1. So I found and interesting article explaining how any folder could be configured with the same behavior as the ‘App_Code’ directory with a the simple xml change in the web.config listed below. Unfortunately this did not fix the problem, but could come in handy in the future.

<configuration>
<system>
<compilation>
<codesubdirectories>
<add directoryname="Subdirectory"></add>
</codesubdirectories>
</compilation>
</system>
</configuration>

3. Finally, I found the problem was that the build option on the class file was set to ‘Content’ rather than ‘Compile’. This made me curious of the different settings available and how they can be used. Here are my initial impressions of each.

  • Content - includes the file in the build/deployment, but does not compile.
  • Embedded Resource - used for situations where you want to utilize the source of the file (for example javascript source for AJAX). There are mechanisms to access the resource through the URL back on the server. Here is a good article on the subject.
  • Compile - compiles the class when you build/deploy and includes MSIL as part of the source code.
  • None - not sure when you’d use this option

Tags:

PermaLink   E-Mail Article   RSS Comment Feed