473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NullReferenceEx ception in call from c# class to c++ static class when touch web.config file

Thanks for your replies. Last week, I continued working with this problem.
Trying to reproduce the error, I developed a short example and found that
the problem is related to strong name dll.

Following is the example to reproduce it.

I have a C++ project (mixed dll, managed and unmanaged), with classes:
EncodeDecode.cp p, EncodeDecode.h, DecoderRing.cpp as follows:

---------------------------
//EncodeDecode.cp p:

#include "stdafx.h"
#include <string.h>
#include "DecoderRing1.h "
#include "EncodeDecode.h "
EncodeDecode::E ncodeDecode(int theKeyOffset)
{
keyOffset = theKeyOffset;
}
char* EncodeDecode::E ncode(char* pMessage)
{
char* pEncoded = new char[strlen(pMessage ) + 1];
char* pDest = pEncoded;
char* pSource = pMessage;
while (*pSource != '\0')
{
*pDest = *pSource + keyOffset;
pSource++;
pDest++;
}
*pDest = '\0';
return pEncoded;
}
char* EncodeDecode::D ecode(char* pMessage)
{
char* pDecoded = new char[strlen(pMessage ) + 1];
char* pDest = pDecoded;
char* pSource = pMessage;
while (*pSource != '\0')
{
*pDest = *pSource - keyOffset;
pSource++;
pDest++;
}
*pDest = '\0';
return pDecoded;
}
---------------------------
//EncodeDecode.h
#pragma once
__nogc
class EncodeDecode
{
private:
int keyOffset;
public:
EncodeDecode(in t theKeyOffset);
char* Encode(char* message);
char* Decode(char* message);
};
---------------------------
//DecoderRing.cpp
// This is the main DLL file.
#include "stdafx.h"
#include <string.h>
using namespace System;
#include "EncodeDecode.h "
#include "DecoderRin g.h"
using namespace System::Runtime ::InteropServic es;
class String2Char
{
char* m_sptr;
public:
String2Char(Str ing* s)
{
IntPtr* m_ptr =__nogc new
IntPtr(System:: Runtime::Intero pServices::Mars hal::StringToHG lobalAnsi(s));
m_sptr = strdup((char*)m _ptr->ToPointer()) ;
delete m_ptr;
}
~String2Char()
{
free(m_sptr);
}
operator char* ()
{
//return (m_sptr =
(char*)m_ptr.To Pointer());
return (m_sptr);
}
};
public __gc class DecoderRing
{
public:
static String* Encode(String* message)
{
char* pEncoded = (new
EncodeDecode(3) )->Encode(String2 Char(message));
String* encodedString =
Marshal::PtrToS tringAnsi(pEnco ded);

delete pEncoded;
return encodedString;

}
static String* Decode(String* message)
{
char* pDecoded = (new
EncodeDecode(3) )->Decode(String2 Char(message));
String* decodedString =
Marshal::PtrToS tringAnsi(pDeco ded);
delete pDecoded;
return decodedString;
}
};
---------------------------
// DecoderRing.h
#pragma once
#include <stdlib.h>
---------------------------

In this project, Confguration properties->C/C++->Command line=
/O2 /AI "Release" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_WINDLL" /FD /EHsc
/GS /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /clr /TP /FU
"C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \mscorlib.dll" /FU
"C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \System.dll" /FU
"C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \System.Data.dl l"

Confguration properties->Linker -> Command Line=
/OUT:"Release\En codeDecode.dll" /INCREMENTAL:NO /NOLOGO /DLL
/INCLUDE:"__DllM ainCRTStartup@1 2" /DEBUG /PDB:"Release/EncodeDecode.pd b"
/NOENTRY /FIXED:No msvcrt.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib
Aditional options= /noentry /NODEFAULTLIB:LI BCMT
This project make the EncondeDecode.d ll

I have a second dll: MyCrypto.dll
//MyCrypto.cs
using System;
namespace ManagedDll
{
public class DataStoreUtil_2
{
public static string LoadDataStores( string msg)
{
return (new MyCrypto()).Dec ode(msg);
}
}
public class MyCrypto
{
public string Decode(string msg)
{
string res1=DecoderRin g.Encode(msg);
return res1;
}
}
}
I make MyCrypto.dll with MyCrypto.rsp=
/t:library
/w:0
/debug
/out:bin\MyCrypt o.dll
/r:bin\log4net.d ll
/r:Mixed\Release \EncodeDecode.d ll
/r:system.dll
MyCrypto.cs
AssemblyInfo.cs (**)

And I have a dll for the aspx=
//simplehandler.c s
using System.Web;
using System;
using ManagedDll;
namespace Programs
{
public class simplehandler : IHttpHandler
{
public void ProcessRequest( HttpContext context)
{
try
{
string res1 =
DataStoreUtil_2 .LoadDataStores ("test");
context.Respons e.Write("<br>re s1=" + res1 +
"<br><br> ");
context.Respons e.Write("<br><b r>Hello
World");

}
catch(Exception e)
{
context.Respons e.Write("<br>er ror=" +
e.Message + "<br><br> " + e.StackTrace);
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
}
The web.config file=
<configuratio n>
<system.web>
<trace enabled="true" />
<identity impersonate="tr ue" />
<httpHandlers >
<add verb="*" path="*.aspx"
type="Programs. simplehandler,s implehandler" />
</httpHandlers>
</system.web>
</configuration>

To reproduce the error:
1) Go to http://localhost/services/simplehandler.aspx (this is OK, you can
see the message "hello world"),
2) Restart the aspnet_wp process (windows task manager),
3) Press F5 in page 1) (this is OK)
4) Modify web.config file (Add to it a blank space for example),
5) F5 in page 1) => The following error appears = Object reference not set
to an instance of an object. at ManagedDll.MyCr ypto.Decode(Str ing msg).
This error (step 5) only appears when AssemblyInfo.cs (**) have a
AssemblyKeyFile (is a strong name dll), but doesn't appear when it isn't a
strong name dll.

Any help or direction regarding the resolution of this problem is welcomed.
Thanks in advance.
Nov 18 '05 #1
2 2127
Hi AAguiar,

Thank you for using Microsoft Newsgroup Service. Currently, I found that
this post is a duplicated one with another one in the queue, and I'll reply
you in the other post. Please feel free to follow in that post.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Thanks Steven.

It's true that I sent this same post with a different subject, but then I
thought that it would be better to write with the same subject like in the
olders emails so as to continue the original thread.

I'll be waiting for any reply in the other post.
Thank you.
"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:5f******** ******@cpmsftng xa07.phx.gbl...
Hi AAguiar,

Thank you for using Microsoft Newsgroup Service. Currently, I found that
this post is a duplicated one with another one in the queue, and I'll reply you in the other post. Please feel free to follow in that post.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9147
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
0
2270
by: Yoni Rabinovitch | last post by:
Hi, I am new to C#, so I apologise if this is a stupid question. I have some 3rd party C++ code, which gets built as static libraries (not DLLs). I want to create a C# form, which will call the C++ code. So, I understand that I need to create a Managed C++ Wrapper, for any
1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
1
3220
by: sunil s via DotNetMonster.com | last post by:
Hi, I've got a native C++ app which calls a 3rd parth .NET DLL using the LoadLibrary/GetProcAddress functions. This works fine when the DLL is located in the app directory, but if I move it out to it's own directory, then I get a FileNotFoundException. I've tried manipulating the app.exe.config file's <codebase> parameter, but this doesn't seem to have any effect, possibly because the DLL does not have a strong name. The only thing...
10
3491
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get { return dbConnectionString;
2
3201
by: Enrico Pangan | last post by:
I'm trying to call some functions in a C++ Dll, "Library.dll" from C#. Some functions work but some return the NullReferenceException. I have here the source code for the C++ version and for the C# version. The C++ version works while the C# version returns the NullReferenceException on a call to Connect(). The Open() and Close() functions works on both C++ and C# version. The Connect() function only works using C++.
13
4154
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
5
555
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when it is invoked by pressing "F5", or when the web.config file is modified. In all these cases the web.config file contains <identity impersonate="false" />. The mysterious problem arrises when I set <identity impersonate="true"/> in the...
1
17557
by: r035198x | last post by:
This exception occurs often enough in practice to warrant its own article. It is a very silly exception to get because it's one of the easiest exceptions to avoid in programming. Yet we've all got it before, lending proof to Einstein's statement: “Only two things are infinite, the universe and human stupidity ...”. Main Cause Dereferencing null. This is by far the more common cause of getting the exception. Reference types in both...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.