C# - Dll's Loaded Through Reflection - Phantom Bug?

Jun 8, 2010

I got a strange one here and I want to know if any of you have ever run accross anything like it.

So I've got this web app that loads up a bunch of dll's through reflection. Basically it looks for Types that are derived from certain abstract types and adds them to the list of things it can make.

Here's the weird part. While developing there is never a problem. When installing it, there is never a problem to start with. Then, at a seemingly random time, the application breaks while trying to find all the types. I've had 2 sites sitting side by side and one worked while the other did not, and they were configured exactly(and I mean exactly) the same.

IISRESET's never helped, but this did:

I simply moved all the dll's out of the bin directory then moved them back. That's right I just moved them out of the bin directory then put them right back where they came from and everything worked fine.

Any ideas?

Got some more info

When the site is working I notice this behavior:
After IISRESET it still works, but recycling the app pool will cause it to break.

When the site is broken:
Neiter IISRESET nor recycling the app pool fixes it, but
moving a single dll out then back in fixes it.

Even More Info

So it turns out that IsAssignableFrom is not returning the correct value. I would not have believed it to be true, but I had my logger log the result and the 2 types, and it definitely returned the wrong value. The crazy thing is that the same dll will return different values at different times when comparing the same 2 types. Yet More Info The particular class that IsAssignableFrom fails on in located in a file with other classes. If I move the class to its own file, then everything works fine. However, if it is in the same file as other classes(even if it is in its own namespace block) then the Type reference is all wrong. The Type reference will have the correct name and methods, but it has trouble finding the correct constructor.

View 3 Replies


Similar Messages:

Configuration :: Phantom Data Source And Web.config?

Mar 11, 2010

I have inherited a VS 2008 project that hosts 5 services in a web directory and am attempting to add a new service. The existing services all work well, and my service is working except when I tried to add authentication like the existing services have using the membership.ValidateUser method. The SOAP request runs for ~18 seconds, and an exception (listed in full below) is thrown with a "network-related or instance-specific error". Other services validate the user, run some code and return in about 500 milliseconds, I think it is safe to assume I am hitting a timeout.

What makes this odd is that the new service lives in the same web application directory as the old services. It uses the same web.config file. I had been intensely reading posts and documentation related to the "network-related or instance specific error" until I noticed the Data Source in the connection string was not a name I am familiar with.

I changed the Data Source to be the name of the machine where the services run (thereis a database called membership on there), and I instantly got kicked out with an exception because the database login credentials were incorrect. Still confused as to why the new service would have this problem, I set out to find this data source. Running the SQL 2000 Server Network Utility doesn't list this instance. osql /L only lists the (local) instance. How do I find this instance? Why does my service not see the instance as the other ones do? More information listed below.

Server is Server 2003 Standard SP1, IIS 6

SQL Server 2000 is the DB

Each service is a C# Windows forms project (is there any valid reason to do this?) that has been changed to output a class library.

Services inherit from the webservice class.

A final project in the solution is an ASP.NET web application that has dependencies on all the other projects and hosts the asmx files which simply refer to the C# classes from the other projects.

Authentication is using Membership.ValidateUser against SQL server 2000. The web.config contains this:

[Code]....

The exception is here:

[Code]....

View 8 Replies

C# - Best Way To Get Only Certain Properties Using Reflection?

Oct 21, 2010

I am trying to come up with the best way to get only certain properties from a type using reflection. How can I differentiate the properties from each other?

I understand that I can use binding flags or name. But say I want only a certain four properties. Would the best way be to create a custom attribute for the ones I want then loop through all of the properties to see if they have that attribute?

View 3 Replies

C# - Set Attributes Values Using Reflection?

Jan 29, 2010

I have a class decorated with a attribute ...[DataEntity("MESSAGE_STAGING", EnableCaching = true, CacheTimeout = 43200)] for some requirement,I want to change this value "MESSAGE_STAGING" at run time to "Test_Message_Staging". What is the best possible way to achieve this? Can i use reflection ,Or is there any other way to do this.

View 3 Replies

C# - Get All Properties For A Class Name Using Reflection?

Mar 21, 2011

I am loading the dll as shown below,

Type[] _Type = Assembly.GetAssembly(typeof(StdAdapter)).GetTypes();

Now I want to get all the properties for a particular 'class name' which is being passed as a string.

View 3 Replies

C# - .NET Framework Assemblies In Reflection?

Mar 19, 2011

I have a collection of assemblies using reflection. I want to loop through them, but I would like to ignore the .NET framework or ASP.NET framework DLL's. Is there an attribute on the assembly that marks that its from the .NET framework? Or any other designation?

I was looking at the name, and if the name of the assembly starts with System, Microsoft, or mscorlib, I am ignoring it. But I was wondering if there is a flag I can use to make this even easier?

View 2 Replies

C# - Reflection And Generics Get Value Of Property?

Apr 29, 2010

i am trying to implement a generic method which allows to output csv file

public static void WriteToCsv<T>(List<T> list) where T : new()
{
const string attachment = "attachment; filename=PersonList.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();

[Code]....

but I am not able to get the value of the object's property

View 2 Replies

Configuration :: Reflection + External Dll?

Mar 12, 2010

i have one interface . for which i need to send the input.input can be differe for person to person .i want to create a custom section in app.config .

<customsection url="">
<value1>
<value2>
</customsection>

for this i can create a libaray and do it ..many different libarray for many people with interface inclued in all ..this is want i need to do ...but the problem for me s i dont know wat library he s going to give me .. client will give me only the dll and i hv find the class name and its corresponding custom sectipon and call the interface method and get the output ..Reflection s the way but i dont know how to do it ...

View 2 Replies

C# - Trying To Create Instance Of Class By Using Reflection

Apr 16, 2010

I am trying to create instance of class by using reflection in ASP.net web site. Class ClassName is defined and located in App_code folder. Following line returns null, what could be wrong.

Type type = Type.GetType("NameSpace.ClassName", false, true);

View 5 Replies

C# - Create An Instance Of A Web Control Using Reflection?

Oct 20, 2010

How can I create an instance of a web control at runtime using reflection? I created a series of controls that implement a common interface and I would like to create these controls based on the name of the control which is stored in my database.

I have attempted (and failed) to create an instance of these controls using Activator.CreateInstance in the following ways:

Activator.CreateInstance("MyUserControl")

and

Activator.CreateInstance("ASP","controls_myusercontrol_ascx")

...and both return null.

I've also attempted to simply get the type of the control by trying..

Type t = Type.GetType("controls_myusercontrol_ascx");

and

Type t = Type.GetType("MyUserControl");

...and it returns null.

If I explicitly declare an object as controls_myusercontrol_ascx or MyUserControl, there is no issue -- but it can't be found with reflection.

Is it possible to create web user controls using reflection at run time? If so, how can I?

View 1 Replies

Use Reflection In C# To List The Methods Of An .asmx?

Jul 8, 2010

given a url that references an asmx how would i go about displaying all of their method names? if assembly="http://.../something/something.asmx" and i was trying to display the method names of that service what should i do now that i have gotten myself this far? i cant seem to find a solution among the hundreds of examples ive looked at

public TestReflection(string assembly)
{
Assembly testAssembly = Assembly.LoadFrom(assembly);[code]....

View 6 Replies

C# - Create A New Instance Of A Type Without Reflection?

Jan 14, 2011

I have a function that at the moment takes a Type variable. This function sticks it in a list and such and eventually needs will create a class of that type. Right now I do that with

object o=MyType.GetConstructors()[0].Invoke(new object[0]);

which is pretty hacky and also will not work in medium trust due to reflection(I think). Is there a better way of doing this without reflection? The Type is defined this way as part of a function. I need the class to be created "lazily" because it may not be created in the application if it's not needed. I use it for example like

AddToList(typeof(Whatever));

Note, I'm open to suggestions on changing the function calling. I just need the object to be created lazily and for to store the type(or however to create an object of the type) in a list.

View 3 Replies

C# - Reflection Permission Are Allowed In Medium Trust?

Jan 11, 2011

I want to ask that which methods/classes are allowed in Medium Trust.For example, whether these methods are allowed?

GetProperties,
GetMethods,
Activator.CreateInstance,
Assembly.Version,
AssemblyName.Namez

View 2 Replies

Web Forms :: Reflection And Partial Page Classes?

Feb 8, 2010

I've been tinkering for hours and I can't figure this out. Seems like it should be pretty straight-forward. Is it possible to use reflection to get a reference to a partial page class given the page's name and path so that I can iterate through the page and examine its controls? I am not looking to examine the currently loaded page, but another page within the same website.

View 4 Replies

Custom Validator Dynamic ServerValidate Using Reflection

Jul 4, 2010

I have a UserControl which contains a TextBox and a CustomValidator. I would like to set the CustomValidator.ServerValidate to a method in the page that contains the UserControl I found this code which will allow me to dynamically set the custom validators validation function: cusvCustom.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(MethodName);

The problem is that a string value won't work there. It needs to be a reference to the method. Is it possible to use reflection (or some other method) to get a valid reference to the parent controls method using only the string name of it? The reason I want to use the string value of the method name is so I can place the control on the page thusly: <uc1:TextBoxField ID="tbUserName" runat="server" CustomValidationMethod="ValidateUserName" />

WebUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl.ascx.cs" Inherits="WebApplication1.WebUserControl" %>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Custom Validation Failed" OnServerValidate="CustomValidator1_ServerValidate" />
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Submit" CausesValidation="true" />
WebUsecControl.ascx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl : System.Web.UI.UserControl
{
public ServerValidateEventHandler Validating;
protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs e)
{
if (Validating != null)
Validating(sender, e);
}
}
}
TestPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="WebApplication1.TestPage" %>
<%@ Register Src="~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" OnValidating="WebUserControl1_Validating" />
</div>
</form>
</body>
</html>
TestPage.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//WebUserControl1.Validating += WebUserControl1_Validating;
}
protected void WebUserControl1_Validating(Object sender, ServerValidateEventArgs e)
{
e.IsValid = false;
}
}
}

I did some research and I found Type.GetMethod and MethodInfo but I can't get them to work. Primarily because I don't know the type of the parent control and can't figure out how to get it. EDIT: My code for matt-dot-net. As you can see it's almost an exact duplicate of your code. For whatever reason it does not work for me as I have it here. When I click on the button the page reloads and is the same. When I un-comment the one line though and click the button then I see the error message.

View 1 Replies

Reflection Retrieve Private Methods Of A Class?

Sep 13, 2010

I want to retrieve private (implementation and other) methods of a class which implements an interface and also is derived from (inherits) a base class.

How can I achieve this using reflection? Is there anyother way to achieve this?

This is wat m tryin to do. I need to view these private methods and their contents, I don't want to invoke them.

Dim assembly As System.Reflection.Assembly
Dim assemblyName As String assemblyName = System.IO.Path.GetFullPath("xyz.dll")
assembly = System.Reflection.Assembly.LoadFile(assemblyName)
assembly.GetType("myClass").Getmethods(Bindings.NonPublic)
assembly.GetType("myClass").GetMethods(BindingFlags.NonPublic) isn't working

View 2 Replies

.net - Generic Way Of Checking Property Type Using Reflection

Mar 25, 2011

I am trying to set property value using reflection as below. I wanted to know if there is any generic way of finding the property type instead of doing it int he below way.

string currentlblTxt;
string currentTxt;
Assembly assembly = Assembly.GetAssembly(typeof(myAdapter));
myAdapter currentEventObject = (myAdapter)assembly.CreateInstance(myClassName);
[code]...

View 1 Replies

C# - Populating Dropdown List With Enum Using Reflection?

Mar 29, 2011

I am populating a page with controls reading properties of a class using reflection. If the property type is 'String' I will add a text-box. If the property type is enum I am adding a dropdownlist. Now I have to populate the dropdown options with enums. How can this be done?

Both the enum definition class(Assignment) and the class(classOne) using which I am populating the page with controls are in the same Namespace(MySolution.Data). While looping through classOne properties when the property name is 'SkillLevel' I will have to go to assignment class get the members of enum SkillLevelEnum and populate the dropdown.

Same needs to be done for other dropdowns also.

My Code:

namespace MySolution.Data
{
public class classOne : MyAdapter
{
private string _Model;

[code]....

View 4 Replies

.NET Plugin Architecture Without Using Reflection Or Static Constructors?

Nov 11, 2010

I have an ASP.NET HttpModule that is distributed as a DLL. I badly need a plugin architecture so I can isolate some heavyweight, rarely used features into external .dlls, and speed up/slim up the core functionality.I've experimented with (1) reflection and (2) static constructors.It seems GoDaddy and a few other web hosts prohibit use of Reflection, making #1 useless..NET 4.0 now calls static constructors lazily, eliminating #2.

How can I have a generic plugin registration system that doesn't require C# or VB code to register the plugins? Even a web.config plugin registration list would be fine, but I don't know how to do that without using reflection.

Update: I need this to work in .NET 2.0 as well as higher versions

View 1 Replies

C# - Creating A Generic IList Instance Using Reflection?

Feb 4, 2010

I am trying to create a generic list of objects using reflection. The below code throws an error Cannot create an instance of an interface. . I could change the IList to List and it works fine, but I was wondering if there is way to get this working with an IList.

var name = typeof (IList<T>).AssemblyQualifiedName;
Type type = Type.GetType(name);
var list = Activator.CreateInstance(type);

View 8 Replies

Vb.net - Ascx.designer 'properties' Not Showing Up In Reflection At Runtime?

Jul 2, 2010

I have a very simple setup, single mycontrol.ascx with assoicated mycontrol.ascx.designer.vb and mycontrol.ascx.vb file. mycontrol.ascx embeds a single reference to a custom control: "MyMenu":

<mM:myMenu id="myMenu1" runat="server" />

This has created a protected reference in the mycontrol.ascx.designer.vb file:Protected WithEvents myMenu1 As Global.CustomControls.MyMenuNow, when I breakpoint the Page_Load() event of mycontrol.ascx, and inspect the members returned from the type via:

Me.GetType().GetMembers()

I cannot any reference to myMenu1. If I look at the control with intellisence, the property is accessible:
Me.myMenu1 Can anyone explain exactly what I'm missing and what I need to do to access designer created properties at runtime through reflection?

View 2 Replies

How To Set Text Property Assigned To The Control Created Dynamically Using Reflection

Sep 27, 2010

how to set text property assigned to the control created dynamically usiong reflection?

Type type = Type.GetType(strFullName);

object instance = Activator.CreateInstance(type);
ctrlTemp = (Control)instance;
ctrlTemp.ID = "Hello";
ctrlTemp.Text???
Panel1.Controls.Add(ctrlTemp);

View 2 Replies

Use System.Type.InvokeMember() / Invoke Method Dynamically Using Reflection?

Feb 24, 2011

I understood that we can use System.Type.InvokeMember() to invoke method dynamically using Reflection, but I couldn't get proper example to show how to work on it. Can anyone please explain how to do it in
Visual Studio 2010

Just for practice purpose I have created one class called MathFunctions like below:
namespaceCSHWEB
{
public
class
MathFunctions
{
public
double
SimpleInterest(double
PrinicipalAmount, double
TimePeriod, double RateOfInterest)
{
return
(PrinicipalAmount * TimePeriod * RateOfInterest) / 100.0;
}
}
}

Now,
how can I invoke above method SimpleInterest with its parameters without instantiating the class?

View 1 Replies

When Building A Datagrid Helper How To Access The New Data Annotation Attributes Using Reflection

Feb 3, 2010

So I've eagerly added the System.ComponentModel.DataAnnotations namespace to my model.

I've added things such as:

[Required] [DisplayName("First Name")]
public string first_name {get;set;}

I really like these attributes because they save me from having to write custom T4 and/or modify views heavily. This way, I can regenerate a view confident that it will add the display names I want, etc.

The problem comes in when I started building a DataGrid helper inspired by the one in ASP.NET MVC2 unleashed. In this helper, Stephen uses reflection to get at the column headings.

var value=typeOf(T).GetProperty(columnName).GetValue(item,null) ?? String.Empty;

Well, the trouble is I don't want to retrieve the property name. I want to retrieve the value for the DisplayName attribute.

My first attempt at this was to look inside the Attributes property of the PropertyInfo class. Unfortunately, none of the data annotations show up as an attribute.

Is there a way to retrieve the data annotations using reflection?

View 2 Replies

Web Forms :: Change Action Attribute With Control Adapter Class But Without Reflection

May 24, 2010

I am facing challenge of changing action attribute of html form tag. As my application is on shared hosting (medium trust) environment of godaddy server, I cannot use reflection to get control adapter of html tag page. So, I cannot use the following code in my Url Rewriting module.

[Code]....

Is there any otherway to implement the same functionality without reflection?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved