Hello Billy,
This is a common issue when ASP.NET code PInvokes native DLLs. EldarM from
MSFT has a good blog entry for the topic:
https://blogs.msdn.com/eldar/archive/2006/09/22/how-to-call-c-dll-from-asp-net-c-code.aspx
As is quoted in the blog:
http://groups.google.com/group/micr...df6e0ac06ba/3a472105feb10c22#3a472105feb10c22
There are generally two reasons for the error in ASP.NET PInvoke:
1. The DLL cannot be found
The solution is to make sure that the directory containing the DLL is in the
environment variable ¡°PATH¡±.
For more information, please refer to Chris¡¯s comments in the above link.
2. The code does not have sufficient permissions to call unmanaged codes
To verify this point, Billy, would you try this aspx page in your solution,
and tell me the result of the function ¡°CanCallUnmanagedCode¡±?
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Security" %>
<%@ Import Namespace="System.Security.Permissions" %>
<html>
<script runat="server">
private static bool CanCallUnmanagedCode
{
get
{
try
{
new
SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
}
catch(SecurityException)
{
return false;
}
return true;
}
}
void Page_Load(Object sender, EventArgs e)
{
if (CanCallUnmanagedCode)
Label1.Text = "This page can call unmanaged code.";
else
Label1.Text = "This page can NOT call unmanaged code.";
}
</script>
<body>
<form runat=server>
<asp:Label id="Label1" Text="Label Control" runat="server"/>
</form>
</body>
</html>
Regards,
Jialiang Ge (
[email protected], remove ¡®online.¡¯)
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.