refactoring namespace in RESTFul WCF causes error at runtime - c#

I create a "WCF Service Application" project.
I make the interface, then class, a [DataMember] decorated object, and Global.asax.cs Global class in the same namespace, parentns.mynamespage.
I run this in VStudio IIS Express and everything is great.
.
Then I realize I want to refactor the namespace to parentns.subnamespace.
That is the only change alone in Imyclass.cs (the object also exists in this file), myClass.cs, and Global.asax.cs recompile and F5-run again in VStudio Imyclass
Now I get:
"the remote server returned an error: (500) Internal Server Error"
Nothing is reported of interest in the Output window except a very generic
"Exception thrown: 'System.Net.WebException' in System.dll"
If I Ctrl-Z everything and rerun everything works again.
What else am I needing to refactor?
How do you troubleshoot this?
Thanks for you help

Sorry. Immediately after posting this question I had the thought to search-and-replace.
I found a reference in the primary global file 'Global.asax' pointing to the old namespace. Updated that and everything works fine.
Thanks.

Related

Why did this accessibility not cause a problem until it was deployed on another PC?

I have a project that when I gave the built .exe to another user, it failed. After some investigation, the reason it was failing was because one of the classes had unspecified accessibility. I.e. class Db. After changing this to public class Db, the problem was solved.
The file structure is as follows:
Solution File.sln
Form1.cs
Controller.cs
Model.cs
Db.cs
The only reason I discovered the possibility this was an issue was due to the JIT debugger, when the exe crashed on the other machine:
System.TypeInitializationException: The type initializer for "Db" threw an exception at Db..cctor()
I ran the same exe on my machine with no issue, and even when I stepped through it using the VS debugger, it didn't have any issues with the (lack of) access to the class.
Why did this run on my machine, but not on another's?

Compiler Error Message: CS0234 namespace not found

I'm getting a compiler error with the Service Reference I've added to the .NET project. The second image show that the Service reference is defined at namespace Jwaala.Site.User.coopBetaServiceTokenProvider, yet I'm still getting a complier error, why?
Ideally there should be a service layer which will handle these WCF connections , that should be ideal/first step to fix.

SoapException ---> Unable to cast object of type 'x' to type 'x'

I've been pulling out my hair on this and I'm pretty much bald at this point.
Background:
Web Service works on my development machine no problem. Deployment to other machines results in the above error when called.
In code, I have a web reference to an authorize.net API. Within it is a method that returns a response of type "CreateCustomerProfileTransactionResponseType". The parameters that it requires are of type MerchantAuthenticationType, CustomerProfileType, and ValidationModeEnum.
Where everything blows up is on the method that is supposed to return the above CreateCustomerProfileTransactionResponseType. I get the error:
What baffles me is that this isn't thrown on my machine (even when mimicking a live environment - No Visual Studio involved) but thrown on any other machine. My machine is a Windows 7 machine. I get failures deploying to 2 separate Windows Server 2008 R2 boxes. I've tried reboots, turning off UAC, etc but to no avail. I've even went so far as to cast the parameter it's complaining about to the object type that it's expecting but the error remains the same. Coding wise, The project is set up as follows:
Application calls a Gateway webservice
Gateway webservice checks web.config entry for what DLL to load and it's location
Gateway itself loads .dll using LoadFrom
Loaded dll runs my method (in this case to capture a payment) which uses the web reference to an authorize.net API
Response is returned to Application that calls it
Any help would be greatly appreciated as I've exhausted all other help avenues.
Thanks,
Check the version of the assembly which contains the type 'x'. Maybe another version of it installed in GAC.
Also check this: Unable to cast object of type MyObject to type MyObject
I figured it out. I had the .dll that I was loading (using Reflection) both in a specified location AND the bin directory of where the web service was. Seems to be a big no no. Removing the .dll from the bin directory solved my issues.

Intellisense errors in Visual Studio

I've made a modular application and each module is a separate project, they are of similar appearance to MVC areas.
I implemented a custom WebViewPage but even after removing the pointer from web.config back to default the intellisense is still dysfunctional.
On the first line of my razor view:
#model IEnumerable<Module2.Models.TestModel>
I get the warning:
xxx\Module2\Views\Shared\TestModelTable.cshtml: ASP.NET runtime error: The pre-application start initialization method Run on type
WebActivator.ActivationManager threw an exception with the following
error message: Exception has been thrown by the target of an
invocation.. xxx\Module2\Views\Shared\TestModelTable.cshtml
And the error:
The name 'model' does not exist in the current context xxx\Module2\Views\Shared\TestModelTable.cshtml
Then each time I try to reference the model an error appears:
The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.HtmlHelper,
System.Linq.Expressions.Expression>)'
cannot be inferred from the usage. Try specifying the type arguments
explicitly. xxx\Module2\Views\Shared\TestModelTable.cshtml 26 14 Module2
Additionally if I add ViewBag.Title to the view I get this error:
One or more types required to compile a dynamic expression cannot be found. Are you missing a
reference? xxx\Module2\Views\Shared\TestModelTable.cshtml
I would assume there was is a problem with the web configs but they are standard web configs found in mvc areas (I removed the custom WebPageView)
This happens for every view I try to create in each module, however the main application works fine. As a result I attempted to copy the webconfigs from the main application to the module but I still had a lot of errors.
Update 6/12/12
After fixing the implementation of RazorBuildProvider to handle modules the app can now successfully render strongly typed views. However the intellisense still renders these errors. I suspect the first error on the #module... line is the culprit and is preventing the editor from loading the required information for the strongly typed model.
Update 6/12/12
Via a process of elimination I've figured out that ninject's PreApplicationStartMethod is the culprit. When the method calls RegisterServices my moduleloader is called and an error is thrown somewhere in there. [assembly: WebActivator.PreApplicationStartMethod(typeof(Frontline.App_Start.NinjectWebCommon), "Start")]
For a better solution i need to figure out how to debug this error properly, I couldn't find anything so I've posted another (more generic) question on SO Debugging Visual Studio editor exceptions
I'll also post my hacky fix as an answer
So I haven't been able to solve the root of the problem but i have a quick fix.
I'm killing the process during my module loading method if it has visual studio in the name:
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.Contains("VisualStudio"))
return;

Why do I get this error in a WebServices project?

I have a ClickOnce app that accesses a bunch of web services. On the client, I have one project that wraps all the web services.
In the Properties for that project, if Build/Generate Serialization Assembly is Auto (which is the default), then everything works fine. I set the option to On, it compiles fine, then during runtime I get this error:
Line 786: [WebMethod]
Line 787: public CC.DTO.AdvertiserAssignmentRevenueDTO[] SearchAdvertiserAssignmentRevenue(byte[] AdvAssgnRevenueSearchFilter)
Line 788: {
Line 789: try
The Detailed Compiler Output is basically "CS0234: The type or namespace name 'DTO' does not exist in the namespace 'CC' (are you missing an assembly reference?)"
Why is this happening?
Just FYI, this is a .NET 2.0 project running in VS2008.
I had a very similar error message with the same symptoms. For me it would even run locally but not on a different server. It turned out I was missing a data contract declaration on one of my methods.
[DataContract (Namespace = ...)]
Double check your methods on the service and client to ensure they have all the needed attributes and declarations.

Categories